#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on Mon, 17 Jan 2000 19:30:36 +0000
# Hacked into netsaint shape by bjb.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/netsaint
NAME=netsaint
DESC=netsaint
NICENESS=5

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	rm -f /var/log/netsaint/rw/netsaint.cmd
	nice -$NICENESS \
		start-stop-daemon --start --quiet \
		 --pidfile /var/run/netsaint/$NAME.pid \
		--make-pidfile --background --exec $DAEMON -- /etc/netsaint/netsaint.cfg
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile /var/run/netsaint/$NAME.pid \
		--oknodo --exec $DAEMON
	echo "$NAME."
	rm -f /var/run/netsaint/$NAME.pid
	rm -f /var/log/netsaint/rw/netsaint.cmd
	;;
  reload|force-reload)
	echo "Reloading $DESC configuration files."
	# Check first
	if $DAEMON -v /etc/netsaint/netsaint.cfg >/dev/null 2>&1 ; then
		start-stop-daemon --stop --signal 1 --quiet --pidfile \
			/var/run/netsaint/$NAME.pid --exec $DAEMON
	else
		echo "Errors in config file. Not reloading."
	fi
  	;;
  restart)
	echo -n "Restarting $DESC: "
	if $DAEMON -v /etc/netsaint/netsaint.cfg >/dev/null 2>&1 ; then
		start-stop-daemon --stop --quiet --pidfile /var/run/netsaint/$NAME.pid \
			--oknodo --exec $DAEMON || true
		sleep 2

		nice -$NICENESS \
			start-stop-daemon --start --quiet \
			--pidfile /var/run/netsaint/$NAME.pid --background --make-pidfile \
			--exec $DAEMON -- /etc/netsaint/netsaint.cfg
		echo "$NAME."
	else
		echo "Errors in config file. Not restarting."
	fi
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
