#!/bin/sh
#
#ident	"@(#)cl_event	1.3	02/08/02 SMI"
#
# Copyright 2001-2002 by Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# usr/src/cmd/initpkg/init.d/cl_event

# Start/stop cl_eventd

SERVER=/usr/cluster/lib/sc/cl_eventd

case "$1" in
'start')
	# test whether we are a cluster and exit if not a cluster
	/usr/sbin/clinfo > /dev/null 2>&1
	if [ $? != 0 ] ; then
		exit 0
	fi

	# We only allow one cl_eventd running at a time
	/usr/bin/pgrep -u 0 -P 1 -x cl_eventd > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		/usr/bin/logger -p local0.err -t CL_EVENT "Error: ${SERVER} is already running."
                exit 1;
	fi

	#
	# make sure that /var/run is mounted, because it is used by the
	# sysevent doors stuff.  grep will return 0 if it has a match,
	# otherwise it will return a non-zero error code.
	#
	/usr/sbin/mount | grep /var/run > /dev/null 2>&1
	if [ $? != 0 ] ; then
		/usr/bin/logger -p local0.err -t CL_EVENT "Error: /var/run is not mounted; cannot start cl_eventd."
		exit 1
	fi

	#
	# Start under PMF with 4 retries and a two minute failure period.
	# If there are more than 4 failures in a two minute period, the pmf
	# will stop attempting to restart the daemon.
	#
	/usr/cluster/bin/pmfadm -c cl_event -t 2 -n 4 ${SERVER}

	if [ $? -ne 0 ]; then
		/usr/bin/logger -p local0.err -t CL_EVENT "Error: Can't start ${SERVER}."
		exit 1
	fi

	;;

'stop')
	# Send SIGKILL via PMF
	/usr/cluster/bin/pmfadm -s cl_event 9

	;;
*)
	echo "Usage: /etc/init.d/cl_event { start | stop }"
	;;
esac
