#!/bin/sh
# $Id$
#
# Description:	Basic, safe panic script after split brain detection
#
# Platform:	Solaris/Unix
#
# Author:	High-Availability.Com Ltd
#

#
# standard variables and functions
#
. /opt/HAC/bin/rsf.sh

DELAY=10	# heartbeat poll time/delay before panic

service=${RSF_SERVICE:-"service_name"}
script="`basename $0`"

#
# args: <start|stop|panic> [no_of_attempts]
#
state=$1
attempts=${2:-'1'}	# no of attempts at this action

#
# you may or may not want this test
#
if [ ${attempts} -gt 3 ]; then
	# fail after three goes
	dated_echo "${service}: Too many retries on ${state}, aborting"
	exit ${RSF_ABORT}	# abort code
fi

#
# decide action based on first argument
#
case "${state}" in

# start and stop are null
'start')
	dated_echo "Starting"
	#
	# startup commands here
	#
	;;

'stop')
	dated_echo "Stopping"
	#
	# shutdown commands here
	#
	;;

'panic')
	dated_echo "*** FATAL ERROR: split brain detected, dying in ${DELAY} seconds!!!"
	sleep ${DELAY}	# allow time for heartbeats
	# pick one:
	uadmin 1 6	# immediate power-off, Solaris
	# halt
	# reboot
	exit ${RSF_EXEC}
	;;

*)
	echo "Usage: $0 <start|stop|panic>"
	exit ${RSF_WARN}	# warning code
	;;

esac

exit 0	# OK code (default)
