#! /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 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/antzc_dispatcher
DAEMON_OPTS="/etc/antzsystem/dispatcher.conf > /dev/null 2>&1 "
NAME=antzsystem
DESC=dispatcher
PIDFILE="/var/run/antzsystem/dispatcher.pid"

test -x $DAEMON || exit 0

# Include antzsystem defaults if available
if [ -f /etc/default/antzsystem ] ; then
	. /etc/default/antzsystem
fi


case "$1" in
  start)
	echo -n "Starting $DESC: "
	if [ -r "$PIDFILE" ]; then
		echo "already running..."
		exit 1;
	fi
	antzc_removeshm > /dev/null 2>&1
	start-stop-daemon --start --quiet -c $USER --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS 
	sleep 3;
	echo "Now running all modules from /etc/antzsystem/init.d"
	for i in `ls /etc/antzsystem/init.d`; do
		echo "Running $i"
		/etc/antzsystem/init.d/$i start force
		sleep 3
	done;
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON -R 10/-9/5
	antzc_removeshm > /dev/null 2>&1
	rm -f $PIDFILE
	echo "$NAME."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: "
	set +e; $0 stop; set -e
	$0 start
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
