linux/scripts/init/inithelpers/daemon.sh

46 lines
715 B
Bash

#!/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'
exit 7
fi
local CMDX="$2"
if [ -z "$CMDX" ]; then
echo "$USAGE" >&2
echo 'Need <daemon>' >&2
exit 2
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"
;;
*)
echo "$USAGE" >&2
exit 2
esac