#!/bin/sh
# RedHat startup script for a Zope instance using zopectl
#
# chkconfig: 2345 80 20
# description: Zope, the web application server

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

zopectl="/usr/bin/zopectl"
name="zope"
sleep_time=1

[ -f $zopectl ] || exit 1

RETVAL=0

start() {
    gprintf "Starting %s: " "$name" 
    "$zopectl" start > /dev/null
    RETVAL=$?
    # wait for zope startup
    sleep $sleep_time
    # and check if deamon is running
    STATUS=`$zopectl status | grep 'not running'`
    [ "$STATUS" != "" ] && failure "startup" || success "startup"
    echo
    return $RETVAL
}

stop() {
    gprintf "Stopping %s: " "$name" 
    "$zopectl" stop > /dev/null
    RETVAL=$?
    STATUS=`$zopectl status | grep 'not running'`
    [ "$STATUS" != "" ] && success "stop" || failure "stop"
    echo
    return $RETVAL
}

status() {
    "$zopectl" status
    RETVAL=$?
    return $RETVAL
}

case "$1" in
	start)
	    start
	    ;;
	
	stop)
	    stop
	    ;;
	
	restart)
	    stop
	    start
	    ;;
	
	status)
	    status
	    ;;
	    
	*)
	    gprintf "Usage: %s {start|stop|restart|status}\n" "$0"
	    exit 1

esac

exit $REVAL
