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

# Start/stop cl_eventlogd

LOGGER=/usr/cluster/lib/sc/cl_eventlogd

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_eventlogd running at a time
	/usr/bin/pgrep -u 0 -P 1 -x cl_eventlogd > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		/usr/bin/logger -p local0.err -t CL_EVENTLOG "Error: ${LOGGER} 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_EVENTLOG "Error: /var/run is not mounted; cannot start cl_eventlogd."
		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_eventlog -t 2 -n 4 ${LOGGER}

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

	;;

'stop')
	# Send SIGKILL via PMF
	/usr/cluster/bin/pmfadm -s cl_eventlog 15

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