diff --git a/initscripts/howard b/initscripts/howard new file mode 100755 index 0000000..86c6ab7 --- /dev/null +++ b/initscripts/howard @@ -0,0 +1,76 @@ +#! /bin/bash + +### BEGIN INIT INFO +# Provides: howard +# Required-Start: $local_fs $network +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: howard sound monitoring service +# Description: Run howard sound monitoring service +### END INIT INFO + +BINARY=/usr/local/bin/howard +CONFIG=/etc/howard.conf +PIDFILE="/var/run/howard.pid" + + +rv=0 +# Carry out specific functions when asked to by the system +case "$1" in + start) + if [[ ! -e $CONFIG ]]; then + echo "Config file '$CONFIG' is missing" + exit 1 + fi + echo -n "Starting howard... " + OPTS=$(cat $CONFIG | tr '\n' ' ') + $BINARY $OPTS + rv=$? + [[ $rv -eq 0 ]] && echo "ok" || echo "failed" + ;; + stop) + echo -n "Stopping howard... " + if [[ -e $PIDFILE ]]; then + kill $(cat "$PIDFILE") + rv=$? + else + pkill howard + rv=$? + fi + [[ $rv -eq 0 ]] && echo "ok" || echo "failed" + ;; + status) + if [[ -e $PIDFILE ]]; then + pid=$(cat "$PIDFILE") + if ps -p $pid >/dev/null 2>&1; then + echo "howard is running (PID $pid)" + rv=0 + else + realpid=$(pgrep howard) + if [[ $? -eq 0 ]]; then + echo "howard is running (PID $realpid) but pidfile has pid $pid" + rv=0 + else + echo "howard pidfile exists but pid $pid isn't running." + rv=1 + fi + fi + else + realpid=$(pgrep -f $BINARY) + if [[ $? -eq 0 ]]; then + echo "howard is running (PID $realpid) but pidfile is missing." + rv=0 + else + echo "howard is not running." + rv=1 + fi + fi + ;; + *) + echo "Usage: /etc/init.d/howard {start|stop|status}" + exit 1 + ;; +esac + +exit $rv