#!/bin/bash
#
# $Cambridge: hermes/src/prayer/files/init.d/prayer.SRC,v 1.3 2008/09/16 09:59:56 dpc22 Exp $
#
# prayer        This shell script takes care of starting and stopping
#               prayer.
#
# chkconfig: 2345 81 29
# description: Prayer is a Webmail interface
# processname: prayer
# config:  __PRAYER_CONFIG_FILE__
# pidfile: /var/run/prayer.pid

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f __BIN_DIR__/prayer ] || exit 0

RETVAL=0
prog="prayer"

start() {
	# Start daemons.

	echo -n $"Starting $prog: "
	daemon __BIN_DIR__/prayer
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/prayer
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down $prog: "
        # Shut down master process to stop prefork storm
        kill `cat __VAR_PREFIX__/pid/prayer-session.pid`
        kill `cat __VAR_PREFIX__/pid/prayer.pid`
	killproc prayer-session
	killproc prayer
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/prayer
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/prayer ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  status)
	status prayer
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
