#! /bin/bash
#
# cherokee:
# Start the Cherokee Web Server.
#
# http://www.cherokee-project.com/
#

NAME=cherokee
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/lib/cherokee
DAEMON=%sbindir%/cherokee
PIDFILE=%localstatedir%/run/$NAME.pid
CONF=%sysconfdir%/cherokee/cherokee.conf

trap "" 1
export LANG=C
export PATH

test -f $DAEMON || exit 0

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

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

  reload)
    echo -n "Reloading $NAME configuration"
    start-stop-daemon --stop --pidfile $PIDFILE --signal HUP
    ;;

  rotate-logs)
    echo -n "Rotating logs"
    start-stop-daemon --stop --pidfile $PIDFILE --signal USR2
    ;;

  restart)
    echo -n "Restarting the server closing all the opened connections"
    start-stop-daemon --stop --pidfile $PIDFILE --signal USR1
    ;;

  force-restart)
    $0 stop
    $0 start
    ;;

  *)
    echo "Usage: %sysconfdir%/init.d/$NAME {start|stop|reload|rotate-logs|restart|force-restart}"
    exit 1
    ;;
esac

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