#! /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/cherokee
NAME=cherokee

PIDFILE=`grep -i '^PidFile' /etc/cherokee/cherokee.conf | sed -e 's/pidfile[\t ]\+//i'`
if [ "x$PIDFILE" = "x" ];
then
        PIDFILE=/var/run/cherokee.pid
fi

test -x $DAEMON || exit 0

set -e

check_alive() {
    PID=`pidof cherokee`
    if [ "x$PID" = "x" ]
    then
	   echo "no"
		return 0
    fi
    return 1
}

case "$1" in
  start)
	echo -n "Starting web server: $NAME"
	start-stop-daemon --start -b --pidfile $PIDFILE --exec $DAEMON
	;;

  stop)
	echo -n "Stopping web server: $NAME"
	start-stop-daemon --stop --oknodo --pidfile $PIDFILE --exec $DAEMON
	;;

  reload|force-reload)
	echo "Reloading $NAME configuration"
	start-stop-daemon --stop --signal USR1 --pidfile $PIDFILE --exec $DAEMON
  ;;

  restart)
	echo -n "Restarting $NAME configuration"
	start-stop-daemon --stop --oknodo --pidfile $PIDFILE --exec $DAEMON
	sleep 1
	start-stop-daemon --start -b --pidfile $PIDFILE --exec $DAEMON
	;;

  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

if [ $? == 0 ]; then
        echo .
        exit 0
else
        echo failed
        exit 1
fi

exit 0
