Skip to content

Instantly share code, notes, and snippets.

@rmzamora
Last active November 18, 2023 19:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rmzamora/074f58e85c8800cc3b5e19880e4e2d4b to your computer and use it in GitHub Desktop.
Save rmzamora/074f58e85c8800cc3b5e19880e4e2d4b to your computer and use it in GitHub Desktop.
kafka start/stop script
#! /bin/sh
### BEGIN INIT INFO
# Provides: kafka
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: a distributed commit log.
# Description: Apache Kafka is publish-subscribe messaging rethought
# as a distributed commit log.
### END INIT INFO
KAFKA_HOME=YOUR_KAFKA_PATH
KAFKA_LOG=YOUR_KAFKA_LOG_PATH
NAME=kafka
# See how we were called.
case "$1" in
start)
# Start daemon.
echo "Starting $NAME";
nohup $KAFKA_HOME/bin/kafka-server-start -daemon $KAFKA_HOME/etc/kafka/server.properties > $KAFKA_LOG/kafka.log 2>&1 &
;;
stop)
# Stop daemons.
echo "Shutting down $NAME";
pid=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]
then
$KAFKA_HOME/bin/kafka-server-stop 2>&1 &
else
echo "Kafka was not Running"
fi
;;
restart)
$0 stop
sleep 2
$0 start
;;
status)
pid=$(ps ax | grep -i 'kafka\.Kafka' | grep java | 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