Created
October 22, 2018 20:43
-
-
Save jonathanmv/101ab1a520c66b385089a3720a5de3ed to your computer and use it in GitHub Desktop.
kafka as a service amazon linux
This file contains 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/bash | |
#/etc/init.d/kafka | |
#chkconfig: - 99 10 | |
DAEMON_PATH=/home/ec2-user/kafka_2.11-2.0.0/bin | |
DAEMON_NAME=kafka | |
# Check that networking is up. | |
#[ ${NETWORKING} = "no" ] && exit 0 | |
PATH=$PATH:$DAEMON_PATH | |
# See how we were called. | |
case "$1" in | |
start) | |
# Start daemon. | |
pid=`ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}'` | |
if [ -n "$pid" ] | |
then | |
echo "Kafka is already running" | |
else | |
echo "Starting $DAEMON_NAME" | |
$DAEMON_PATH/kafka-server-start.sh -daemon /home/ec2-user/kafka_2.11-2.0.0/config/server.properties | |
fi | |
;; | |
stop) | |
echo "Shutting down $DAEMON_NAME" | |
$DAEMON_PATH/kafka-server-stop.sh | |
;; | |
restart) | |
$0 stop | |
sleep 2 | |
$0 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
This script is based on one published in the Kafka Cluster Setup on Udemy. The script in there was made for Ubuntu but I needed it to run in Amazon Linux. Instead of using update-rc.d it uses chkconfig
Set up kafka as a service so that you can do
sudo service kafka start