kafka-init.j2 1.35 KB
Newer Older
1 2
#!/bin/bash

3 4 5
# Define the user that should run this script.
SCRIPT_USER=kafka

6 7 8 9
# The path where Apache Kafka is installed.
INSTALLATION_PATH="{{ installation_path }}"

# The full path of the pid file to use.
10
PIDFILE="$INSTALLATION_PATH/kafka/kafka.pid"
11 12

# The full path of the lock file to use.
13
LOCKFILE="$INSTALLATION_PATH/kafka/kafka-lock"
14 15 16 17 18

# The command that will start Apache Kafka.
START_COMMAND="$INSTALLATION_PATH/kafka/bin/kafka-server-start.sh $INSTALLATION_PATH/kafka/config/server.properties"

start(){
19
  sudo -u $SCRIPT_USER /sbin/start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE --exec $START_COMMAND
20
  RETVAL=$?
21
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER touch $LOCKFILE)
22 23 24 25
  return $RETVAL
}

stop(){
26
  sudo -u $SCRIPT_USER  /sbin/start-stop-daemon --stop --remove-pidfile --pidfile $PIDFILE
27
  RETVAL=$?
28
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER rm -f $LOCKFILE)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  return $RETVAL
}

restart(){
  stop
  start
}

RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload|force-reload)
    restart
    ;;
  condrestart)
    [ -f $LOCKFILE ] && restart || :
    ;;
  status)
53
    [ -f $LOCKFILE ] && echo "Apache Kafka is running." || echo "Apache kafka is not running."
54 55 56 57 58 59 60 61 62
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    RETVAL=1
esac

exit $RETVAL