Skip to content

Instantly share code, notes, and snippets.

@pedro-stanaka
Forked from superscott/kafka
Last active June 13, 2016 13:41
Show Gist options
  • Save pedro-stanaka/b442417f8ecc8f36d27cc6c17a8f6fe5 to your computer and use it in GitHub Desktop.
Save pedro-stanaka/b442417f8ecc8f36d27cc6c17a8f6fe5 to your computer and use it in GitHub Desktop.
Simple Kafka Ubuntu init.d Startup Script
# Created by https://www.gitignore.io/api/windows
### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
#!/bin/bash
USER=kafka
DAEMON_PATH=/opt/kafka/bin
KAFKA_HOME=/opt/kafka
DAEMON_NAME=kafka
USER=kafka
# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0
start() {
pid=$(ps ax | grep -i 'kafka.kafka' | grep -v grep | awk '{print $1}')
if [[ "x$pid" -ne "x" ]]; then # Service is running
echo "Kafka is already running as $pid"
return 1
fi
echo "Starting $DAEMON_NAME..." >&2
local CMD="$DAEMON_PATH/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties"
/bin/su -c "$CMD" $USER
echo "$DAEMON_NAME started..."
}
stop() {
# Stop daemons.
echo "Shutting down $DAEMON_NAME";
pid=`ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
kill -9 $pid
else
echo "Kafka was not Running"
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
;;
restart)
stop
sleep 2
start
;;
status)
pid=`ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
echo "Kafka is Running as PID: $pid"
else
echo "Kafka is not Running"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment