add init scripts

add mode to write average volume instead of max
add pid file
handle sighup for log rotation
add daemon mode
This commit is contained in:
rob 2022-06-04 15:17:49 +10:00
parent 26c3dda8ea
commit 564a8942d7
1 changed files with 76 additions and 0 deletions

76
initscripts/howard Executable file
View File

@ -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