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

zopectls=$(ls /var/lib/erp5/zeo_client*/bin/zopectl 2>/dev/null)
name="zeo_client"

[ -f $zopectl ] || exit 1

RETVAL=0

start() {
    n=1
    for zopectl in $zopectls; do
      echo -n "Starting $name $n: " 
      "$zopectl" start 2> /dev/null
      RETVAL=$?
      echo
      n=$(($n+1))
    done
    return $RETVAL
}

stop() {
    n=1
    for zopectl in $zopectls; do
      echo -n "Stoping $name $n: " 
      "$zopectl" stop 2> /dev/null
      RETVAL=$?
      echo
      n=$(($n+1))
    done
    return $RETVAL
}

status() {
    n=1
    for zopectl in $zopectls; do
      echo -n "Checking $name $n: " 
      "$zopectl" status 2> /dev/null
      RETVAL=$?
      echo
      n=$(($n+1))
    done
    return $RETVAL
}

logreopen() {
    n=1
    for zopectl in $zopectls; do
      echo -n "Reoping the log file in $name $n: " 
      "$zopectl" logreopen 2> /dev/null
      RETVAL=$?
      echo
      n=$(($n+1))
    done
    return $RETVAL
}

case "$1" in
	start)
	    start
	    ;;
	
	stop)
	    stop
	    ;;
	
	status)
	    status
	    ;;
	
	logreopen)
	    logreopen
	    ;;
	
	restart)
	    stop
	    start
	    ;;
	
	*)
	    echo "Usage: $0 {start|stop|status|logreopen|restart}"
	    exit 1

esac

exit $REVAL
