#!/bin/sh
#
# /etc/rc.d/rc.cherokee
#
# Start/stop/restart the Cherokee web server.
# 
# Script made by: Marco Antonio Islas Cruz <markuz@islascruz.org>
# Modify by: Juan Angulo Moreno <juan@apuntale.com>
#
# To install:
#   copy this file to /etc/rc.d/rc.cherokee
#   and add something like this to your file
#   /etc/rc.d/rc.M or /etc/rc.d/rc.local
#   #  Start the cherokee daemon:
#   if [ -x /etc/rc.d/rc.cherokee ]; then
#     . /etc/rc.d/rc.cherokee start
#   fi
#   make .conf or anothers files in /etc/cherokee (see below)
#
# To install:
#   run: chmod +x /etc/rc.d/rc.cherokee
#
# To uninstall:
#   run: chmod 0644 /etc/rc.d/rc.cherokee

PIDFILE=/var/run/cherokee.pid
CHEROKEE=/usr/sbin/cherokee 

E_CSCH="Cannot Start Cherokee"
E_CHNR="Cherokee is not running"

if [ -f $PIDFILE ]; then
	PID=`cat /var/run/cherokee.pid`
	if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
		RUNNING=1
	else
		RUNNING=0
	fi
else
	RUNNING=0
fi

case "$1" in
   'start')
		if [ $RUNNING -eq 1 ]; then
			echo "Cherokee is already running"
		else
			rm -f $PIDFILE
			$CHEROKEE &
			echo "Starting Cherokee"
			
		fi;;
   'stop')
		if [ $RUNNING -eq 1 ]; then
			kill $PID
			echo "Stopping Cherokee" 
		else
			echo $E_CHNR
		fi;;
   'restart')
		if [ $RUNNING -eq 1 ]; then
			if  kill $PID ; then
				echo "Stopping Cherokee"
			fi
		fi
		$CHEROKEE &
		echo "Starting Cherokee"
		;;	
   *)
      echo "usage $0 start|stop|restart" ;;
esac

