Pacific-Design.com

    
Home Index

1. Apache Kafka

2. init.d

Apache Kafka / init.d /

Start up Kafka on Boot


#!/bin/bash
#
# Start up Kafka on Boot
#-----------------------------------------------------------------------------------------------------------# 
# vi /etc/init.d/kafka
# chmod 755 /etc/init.d/kafka
#
# Adding a Service to Default runlevels
# update-rc.d kafka defaults
# update-rc.d kafka enable
#
# service --status-all 
#-----------------------------------------------------------------------------------------------------------# 

RETVAL=$?
KAFKA_HOME="/opt/kafka_2.9.1-0.8.2.1"

case "$1" in
 start)
        if [ -f $KAFKA_HOME/bin/zookeeper-server-start.sh ];
          then
            echo $"Starting Kafka"

            # Start Zookeper
            /bin/su root $KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties &
            sleep 10;
            # Start Kafka Broker
            /bin/su root $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties &
        fi
        ;;
 stop)
        if [ -f $KAFKA_HOME/bin/kafka-server-stop.sh ];
          then
            echo $"Stopping Kafka"
            /bin/su root $KAFKA_HOME/bin/kafka-server-stop.sh &
            sleep 10;
            /bin/su root $KAFKA_HOME/bin/zookeeper-server-stop.sh &
        fi
        ;;
 *)
        echo $"Usage: $0 {start|stop}"
        exit 1
        ;;
esac


# vi ~/.bashrc
#-------------------------------------------------------------#
export KAFKA_LIB='/opt/kafka_2.9.1-0.8.2.1/libs'

CLASSPATH=.:$KAFKA_LIB/jopt-simple-3.2.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/kafka_2.9.1-0.8.2.1.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/kafka-clients-0.8.2.1.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/log4j-1.2.16.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/metrics-core-2.2.0.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/scala-library-2.9.1.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/slf4j-api-1.7.6.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/slf4j-log4j12-1.6.1.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/snappy-java-1.1.1.6.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/zkclient-0.3.jar
CLASSPATH=$CLASSPATH:$KAFKA_LIB/zookeeper-3.4.6.jar
export CLASSPATH
#-------------------------------------------------------------#