#! /bin/bash
#
# 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
NAME="ultrapossum-server"
DESC="UltraPossum Server"

set -e

test -x "/usr/bin/ultrapossum-config" || exit 0

eval `ultrapossum-config init`

tmp=`tempfile`
trap "/bin/rm -f $tmp; eval `ultrapossum-config term`" 0

case "$1" in
  start)
	if test "x$TYPE" = "xclient"; then
	  exit 0
	fi
	echo -n "Starting $DESC: "
	if $MODULEDIR/server/startup start 2> $tmp; then
	  echo "."
	else
	  echo "failed."
          cat $tmp
	  exit 1
	fi
	;;
  stop)
  	if test "`$MODULEDIR/server/startup status`" = "running"; then
	  echo -n "Stopping $DESC: "
	  if $MODULEDIR/server/startup stop 2> $tmp; then
	    echo "."
	  else
	    echo "failed."
            cat $tmp
	    exit 1
	  fi
	fi
	;;
  #reload)
	#
	#	If the daemon can reload its config files on the fly
	#	for example by sending it SIGHUP, do it here.
	#
	#	If the daemon responds to changes in its config file
	#	directly anyway, make this a do-nothing entry.
	#
	# echo "Reloading $DESC configuration files."
	# start-stop-daemon --stop --signal 1 --quiet --pidfile \
	#	/var/run/$NAME.pid --exec $DAEMON
  #;;
  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: "
	if ! $MODULEDIR/server/startup stop > /dev/null 2> $tmp; then
	  echo "failed."
          cat $tmp
	  exit 1
	fi
	if test "x$TYPE" = "xclient"; then
	  exit 0
	fi
	if $MODULEDIR/server/startup start 2>> $tmp; then
	  echo "."
	else
	  echo "failed."
          cat $tmp
	fi
	;;
  status)
        $MODULEDIR/server/startup status
	;;
  *)
	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
