#!/bin/sh
#
# ZopeX3 Start/Stop the Zope web-application server.
#
# chkconfig: 2345 73 73
# description: ZopeX3 is a web server specifically for handling \
#              HTTP requests to the Zope web-application service.
#
# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE_HOME=/var/lib/zope3
INSTANCE_NAME=`basename ${INSTANCE_HOME}`
START_SHELL=${INSTANCE_HOME}/bin/zopectl
[ -f ${START_SHELL} ] || exit 0

RETVAL=0
case "$1" in
  start)
	echo -n "Starting zope3: "
	#umask 077
	su -l zope3 -c "${START_SHELL} start" > /dev/null 2>&1
	RETVAL=$?
	[ $RETVAL -eq 0 ] && success || failure
  	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/${INSTANCE_NAME}
  	;;
  stop)
	echo -n "Shutdown zope3: "
	su -l zope3 -c "${START_SHELL} stop" > /dev/null 2>&1
	RETVAL=$?
	[ $RETVAL -eq 0 ] && success || failure
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${INSTANCE_NAME}
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  condrestart)
  	[ -f /var/lock/subsys/${INSTANCE_NAME} ] && $0 restart || RETVAL=0
	;;
  status)
	su -l zope3 -c "${START_SHELL} status"
	RETVAL=$?
	[ $RETVAL -ne 0 ] && RETVAL=$?
	;;
  *)
	echo "Usage: zope3 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
