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

3 4 5 6 7 8
# Define the user that should run the service.
SERVICE_USER=kafka

# Define the group in which SERVICE_USER belongs.
SERVICE_GROUP=lambda

9 10 11 12
# The path where Apache Kafka is installed.
INSTALLATION_PATH="{{ installation_path }}"

# The full path of the pid file to use.
13
PIDFILE="$INSTALLATION_PATH/kafka/kafka.pid"
14 15

# The full path of the lock file to use.
16
LOCKFILE="$INSTALLATION_PATH/kafka/kafka-lock"
17 18 19 20 21

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

start(){
22 23 24 25 26
  /sbin/start-stop-daemon --start --background --chuid $SERVICE_USER:$SERVICE_GROUP --make-pidfile --pidfile $PIDFILE --exec $START_COMMAND

  chown $SERVICE_USER $PIDFILE
  chgrp $SERVICE_GROUP $PIDFILE

27 28
  RETVAL=$?
  [ $RETVAL -eq 0 ] && touch $LOCKFILE
29 30 31 32

  chown $SERVICE_USER $LOCKFILE
  chgrp $SERVICE_GROUP $LOCKFILE

33 34 35 36
  return $RETVAL
}

stop(){
37
  /sbin/start-stop-daemon --stop --remove-pidfile --pidfile $PIDFILE
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  RETVAL=$?
  [ $RETVAL -eq 0 ] && $(rm -f $LOCKFILE)
  return $RETVAL
}

restart(){
  stop
  start
}

RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload|force-reload)
    restart
    ;;
  condrestart)
    [ -f $LOCKFILE ] && restart || :
    ;;
  status)
64
    [ -f $LOCKFILE ] && echo "Apache Kafka is running." || echo "Apache kafka is not running."
65 66 67 68 69 70 71 72 73
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    RETVAL=1
esac

exit $RETVAL