#! /bin/sh
#
# skeleton	Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#
### BEGIN INIT INFO
# Provides:          root-system-proofd
# Required-Start:    $local_fs
# Required-Stop:     $local_fs 
# Should-Start:	     $network, $remote_fs, root-file-server
# Should-Stop:	     $network, $remote_fs, root-file-server
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Parallel ROOt Facility Server
# Description:       Parallel ROOt Facility Server to let the node
#		     participate in a PROOF cluster, either as slave or
#		     master. 
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=@prefix@/bin/proofd
NAME=proofd
DESC="Parallel ROOt Facility Server"

test -x $DAEMON || exit 0

# Include root defaults if available
if [ -f @sysconfdir@/default/root-system-proofd ] ; then
	. @sysconfdir@/default/root-system-proofd
fi

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
. /lib/lsb/init-functions

# Check if inetd is controlling proofd
if test -f /var/run/inetd.pid ; then 
    # Inetd is running
    if grep -q ^$NAME /etc/inetd.conf > /dev/null 2>&1 ; then 
	# PROOFD is controlled by inetd. 
	ENABLE_PROOFD=no
    fi
fi
# Check if xinetd is controlling proofd
if test -f /var/run/xinetd.pid ; then 
    # Inetd is running
    if grep -q ^$NAME /etc/inetd.conf > /dev/null 2>&1 ; then 
	# PROOFD is controlled by xinetd. 
	ENABLE_PROOFD=no
    fi
    # old name 
    for i in proofd root-proofd root-system-proofd ; do 
	if test ! -f /etc/xinetd.d/$i ; then continue ; fi 
	if grep "disable[[:space:]]*= *[Nn][Oo]" /etc/xinetd.d/$i \ 
	    > /dev/null 2>&1 ; then
	    # PROOFD is controlled by xinetd. 
	    ENABLE_PROOFD=no
	    break
	fi
    done
fi

# Check if we're enabled
case `echo $ENABLE_PROOFD | tr '[:upper:]' '[:lower:]'` in 
    yes) ;;
    *) exit 0;;
esac

# function to start daemon
startit ()
{
    start-stop-daemon --make-pidfile --start --quiet --pidfile \
	/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS $PROOF_DIR
    ret=$?
    if test $ret -ne 0 ; then 
	echo "Failed" 
	exit 1
    fi
    pidof $DAEMON > /var/run/$NAME.pid 2> /dev/null
    return $ret
}

# function to stop daemon
stopit ()
{
    start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/$NAME.pid \
	--exec $DAEMON
    ret=$?
    if test $ret -ne 0 ; then 
	echo "Failed" 
	exit 1
    fi
    return $ret
}

# Executable code
case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	startit 
	ret=$?
	[ "$VERBOSE" != no ] && log_end_msg $ret
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	stopit
	ret=$?
	[ "$VERBOSE" != no ] && log_end_msg $ret
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	log_daemon_msg "Restarting $DESC" "$NAME"
	stopit
	sleep 1
	startit
	ret=$?
	log_end_msg $ret
	;;
  *)
	N=@sysconfdir@/init.d/root-system-$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
#
# EOF
#