#! /bin/sh -e
#
# 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 #DATE#

VICE=/var/lib/vice
SRV=${VICE}/srv
PID=${SRV}/pid
DESC="Coda server"
NAME="codaserv"

start_server () {
	if [ -f ${PID} ] ; then
		echo " ${NAME} already running (${PID})."
		exit 0
	fi
	if [ ! -f ${VICESRV}/CRASH ]; then
		${STARTSERVER} &
	else
	    echo "$(date): found CRASH, srv not started." >> ${SRV}/SrvErr
	    echo " Found ${SRV}/CRASH file, ${NAME} not started."
	fi
}

stop_server () {
	if [ -f ${PID} ] ; then
		${VOLUTIL} shutdown
		echo -n " Sleeping 30 secs to let $NAME shutdown... "
		sleep 30
	fi
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start_server
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	stop_server
	echo "$NAME."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	stop_server
	start_server
	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
