2014-10-10 16:35:33 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Author: Adrian Kousz, 2014
|
|
|
|
|
|
|
|
USAGE="Usage: $0 {start|stop|restart|status} <pidfile> [<daemon> [<prio> [<umask>]]]"
|
|
|
|
|
|
|
|
. "$(dirname "$0")/fns.sh"
|
|
|
|
|
|
|
|
start() {
|
|
|
|
if is_running "$1"; then
|
|
|
|
echo 'Service already running'
|
2014-10-10 17:53:14 +02:00
|
|
|
exit 7
|
2014-10-10 16:35:33 +02:00
|
|
|
fi
|
|
|
|
local CMDX="$2"
|
|
|
|
if [ -z "$CMDX" ]; then
|
|
|
|
echo "$USAGE" >&2
|
|
|
|
echo 'Need <daemon>' >&2
|
2014-10-10 17:53:14 +02:00
|
|
|
exit 2
|
2014-10-10 16:35:33 +02:00
|
|
|
fi
|
|
|
|
if [ ! -z $4 ]; then CMDX="umask $4; $CMDX"; fi
|
|
|
|
sh -c "$CMDX"
|
|
|
|
if is_running "$1"; then
|
|
|
|
echo 'Service started'
|
|
|
|
if [ ! -z $3 ]; then renice $3 $(cat "$1") 2>&-; fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start "$2" "$3" "$4" "$5"
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop "$2"
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop "$2"
|
|
|
|
start "$2" "$3" "$4" "$5"
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status "$2"
|
|
|
|
;;
|
|
|
|
*)
|
2014-10-10 17:53:14 +02:00
|
|
|
echo "$USAGE" >&2
|
|
|
|
exit 2
|
2014-10-10 16:35:33 +02:00
|
|
|
esac
|