#!/bin/sh
### BEGIN INIT INFO
# Provides:             kandalf
# Required-Start:       $syslog $remote_fs
# Required-Stop:        $syslog $remote_fs
# Should-Start:         $local_fs
# Should-Stop:          $local_fs
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    kandalf - RabbitMQ to kafka bridge
# Description:          kandalf - RabbitMQ to kafka bridge
### END INIT INFO

NAME="kandalf"
DAEMON=/usr/local/bin/kandalf
CONFIGFILE=/etc/kandalf/conf/config.yml
ARGS="-c $CONFIGFILE"
PIDFILE=/var/run/$NAME.pid

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
    start)
        if start-stop-daemon --start -b -q -m -p $PIDFILE -c kandalf:kandalf -x $DAEMON -- $ARGS
        then
            echo "$NAME started."
        else
            echo "$NAME starting failed."
        fi
        ;;
    stop)
        if start-stop-daemon --stop -q -R INT/10/KILL/15 -o -p $PIDFILE
        then
            echo "$NAME stopped."
            rm -f $PIDFILE
        else
            echo "$NAME stop failed"
        fi
        sleep 1
        ;;
    restart)
        ${0} stop
        ${0} start
        ;;
    status)
        status_of_proc -p $PIDFILE $DAEMON $NAME
        ;;
    *)
        echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
        exit 1
        ;;
esac

exit 0
