#!/bin/sh -e

# $Id: init,v 1.1 1998/02/18 02:27:02 roderick Exp $

daemon=/usr/sbin/mon
cfg=/etc/mon.cf
pid=/var/run/mon/mon.pid
user=daemon
desc='monitor daemon'
name=mon

[ -f $daemon -a -f $cfg ] || exit 0

# Don't bother if the user hasn't configured the package, there is no
# default configuration but there is a default config file (which just
# contains comments).

egrep -v '^[ 	]*$|^#' $cfg >/dev/null || exit 0

[ $# = 1 ] || {
    echo "$0: wrong number of args (got $# expected 1), args are:" "$@" >&2
    exit 1
}

action=$1
set -- --pidfile $pid --startas $daemon -- -f

case x-$action in
    x-start)
	echo -n "Starting $desc: $name"
	su $user -- -c '"$@"' x start-stop-daemon --start "$@"
	echo .
	;;
    x-stop)
	echo -n "Stopping $desc: $name"
	start-stop-daemon --stop --oknodo --quiet "$@"
	echo .
	;;
    x-restart)
    	echo -n "Restarting $desc: $name"
	start-stop-daemon --stop --oknodo --quiet "$@"
	su $user -- -c '"$@"' x start-stop-daemon --start "$@"
	echo .
	;;
    x-reload | x-force-reload)
	echo "Reloading $desc configuration files."
	start-stop-daemon --stop --signal 1 "$@"
	;;
    *)
    	echo "$0: invalid action \`$action'" >&2
	exit 1
	;;
esac

exit 0
