#!/bin/bash
#
# TODO:
# To be in perfect debian style we should use start-stop-daemon also
# for chrooting.
#
#
### some default values ###
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DEFAULT_DAEMON=/usr/bin/freepopsd
DEFAULT_PIDFILE=/var/run/freepopsd.pid
DEFAULT_CHROOTED_DAEMON_OPTS=" -n -s nobody.nogroup"
DEFAULT_DAEMON_OPTS=" -n"
NAME=freepopsd
DESC="freepops daemon"
### /etc/default/ loading ###
# Include freepops defaults if available. Used variables are:
# DAEMON, DAEMON_OPTS, CHROOTED_DAEMON_OPTS, PIDFILE, CHROOT
# all have a DEFAULT_ here, except CHROOT that is empty if the
# daemon should run in the normal environment
if [ -f /etc/default/freepops ] ; then
. /etc/default/freepops
fi
if [ -z "$DAEMON" ] ; then
DAEMON=$DEFAULT_DAEMON
fi
if [ -z "$PIDFILE" ] ; then
PIDFILE=$DEFAULT_PIDFILE
fi
if [ -z "$DAEMON_OPTS" ] ; then
DAEMON_OPTS=$DEFAULT_DAEMON_OPTS
fi
if [ -z "$CHROOTED_DAEMON_OPTS" ] ; then
CHROOTED_DAEMON_OPTS=$DEFAULT_CHROOTED_DAEMON_OPTS
fi
test -x $DAEMON || exit 0
set -e
### helpers ###
start_freepopsd () {
if [ -z "$CHROOT" ] ; then
start-stop-daemon --start -b --quiet -m -p $PIDFILE \
--exec $DAEMON -- $DAEMON_OPTS
else
echo -n "(chroot) "
start-stop-daemon --start -b --quiet -m -p $PIDFILE \
-r $CHROOT --exec $DAEMON -- $CHROOTED_DAEMON_OPTS
fi
}
stop_freepopsd () {
if [ -z "$CHROOT" ] ; then
start-stop-daemon --stop --quiet -p $PIDFILE
else
echo -n "(chroot) "
start-stop-daemon --stop --quiet -p $PIDFILE
fi
rm $PIDFILE
}
### real code ###
case "$1" in
start)
echo -n "Starting $DESC: "
start_freepopsd
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_freepopsd
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
stop_freepopsd
sleep 1
start_freepopsd
echo "$NAME."
;;
*)
N=/etc/init.d/freepops
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
syntax highlighted by Code2HTML, v. 0.9.1