#!/bin/sh
#
# zope          Start/Stop the Zope web-application server.
#
# chkconfig: 2345 72 72
# description: zope is a web server specifically for handling \
#              HTTP requests to the Zope web-application service.
# probe: true

# Source function library.
. /etc/rc.d/init.d/functions

ZOPE_HOME=/usr/lib/zope
INSTANCE_HOME=/var/lib/zope
INSTANCE_NAME=`basename ${INSTANCE_HOME}`

RETVAL=0

# See how we were called.
case "$1" in
    start)
	if [ -f /var/lock/subsys/zope ]; then
		msg_Already_Running Zope
	else 	
		msg_starting Zope
		busy
		daemon zope-zserver
		RETVAL=$?;
		sleep 5
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zope
	fi
	;;
  stop)
        if [ -f /var/lock/subsys/zope ]; then
                msg_stopping Zope
                kill `cat ${INSTANCE_HOME}/Z2.pid`
		sleep 1
		deltext
		ok
                rm -f /var/lock/subsys/zope >/dev/null 2>&1
        else
                msg_not_running Zope
                exit 1
        fi
	;;
  status)
	if ps -p `cat ${INSTANCE_HOME}/Z2.pid | awk '{print $2}'` >/dev/null; then
	    RETVAL=$?
	    echo "Zope (pid `cat ${INSTANCE_HOME}/Z2.pid`) is running"
	else     
	    msg_not_running Zope
	    RETVAL=1
	fi
    
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
	msg_Usage "$0 {start|stop|status|restart}"
	exit 1
	;;
esac

exit $RETVAL
