linux/scripts/init/inithelpers/regular.sh

49 lines
854 B
Bash

#!/bin/sh
# Author: Adrian Kousz, 2014
USAGE="Usage: $0 {start|stop|restart|status} <pidfile> [<logfile> <user> <daemon> [<prio> [<umask>]]]"
. "$(dirname "$0")/fns.sh"
start() {
if is_running "$1"; then
echo 'Service already running'
exit 7
fi
local CMDX="$4"
if [ -z "$CMDX" ]; then
echo "$USAGE" >&2
echo 'Need <daemon>' >&2
exit 2
fi
date >> "$2"
chown $3:adm "$2"
CMDX="$CMDX >> '$2' 2>&1 & echo \$!"
if [ ! -z $6 ]; then CMDX="umask $6; $CMDX"; fi
su -s /bin/bash -c "$CMDX; disown" $3 > "$1"
if is_running "$1"; then
echo 'Service started'
if [ ! -z $5 ]; then renice $5 $(cat "$1") 2>&-; fi
fi
}
case "$1" in
start)
start "$2" "$3" "$4" "$5" "$6" "$7"
;;
stop)
stop "$2"
;;
restart)
stop "$2"
start "$2" "$3" "$4" "$5" "$6" "$7"
;;
status)
status "$2"
;;
*)
echo "$USAGE" >&2
exit 2
esac