#! /bin/sh
### BEGIN INIT INFO
# Provides: SEDA Message Bus
# Required-Start:    $local_fs $syslog $remote_fs dbus
# Required-Stop:     $local_fs $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Manage SEDA Message Bus daemon
### END INIT INFO
#
# seda_bus    SEDA Message Bus
#
# Brian Taylor <brian@resolvingarchitecture.io>
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=seda_bus
DESC="Staged Event-Driven Architectural (SEDA) Message Bus"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"

# binary path
DAEMON="/usr/bin/seda_bus"

# Path of your php script
DAEMON_OPTS="--persist-queues=false"

START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"

test -x $DAEMON || exit 0

set -e

case "$1" in
start)
echo -n "Starting $NAME..."
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME Running."
;;
stop)
echo -n "Stopping $NAME..."
start-stop-daemon $STOP_OPTS
echo "$NAME Stopped."
rm -f $PIDFILE
;;
restart|force-reload)
echo -n "Restarting $NAME..."
start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME Restarted."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0
