#!/bin/sh
#
# Annex ERPCD daemon startup and shutdown script for /etc/init.d
#
# should be linked to appropriate files in /etc/rc[02]
#
# Intended for UMAX V (and possibly other SysV.3 systems)

USAGE="Usage: /etc/init.d/annex-initd {start | stop}"

if [ ! -d /usr/bin ]
then			# /usr not mounted ??
	exit 
fi

case "$1" in
'start')
	#
	# These commands bring up the Annex-related network daemons
	#

	echo "starting Annex network daemons"

	#
	# Define enough ulimit for erpcd to handle large crash dump files
	#

	( ulimit 65536; /etc/erpcd ) # Expedited Remote Procedure Call Daemon
	
	echo "Annex network daemon startup complete"
	;;

'stop')
	#
 	# kill the Annex daemons if any are still running
	#

	killdemon() {
 		pid=`/bin/ps -ef 2>/dev/null \
			| /usr/bin/egrep $1 | /bin/grep -v grep \
 			| /bin/sed -e 's/  *[a-z0-9]*  *//' -e 's/ .*//'`
 		if [ "${pid}" != "" ]
 		then
			echo killing Annex network daemons $1
 			/bin/kill -$2 ${pid}
			sleep $3
 		fi
	}
	killdemon erpcd 15 2
	killdemon erpcd  1 2
	killdemon erpcd  9 1

	;;
*)
	echo ${USAGE}
	exit 1
	;;
esac
