-
-
Save iskandarsaleh/82e0ad61f5d5c6b0847a511ad19d6f4b to your computer and use it in GitHub Desktop.
kafka start/stop script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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