#!/bin/sh
#
# Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# SNDR start script
#
# Description:	This is the SNDR start script. It must be located
#		in /etc/init.d with links to the appropriate rc2.d and
#		rc0.d files.
#		It can also be used to start or stop a specified cluster
#		resource group when invoked from the data service cluster
#		failover script.
#
#ident  "@(#)rdc 1.37     05/08/09 SMI"
#
#
#
PATH=/etc:/bin
RDCBIN="/usr/opt/SUNWesm/SUNWrdc/sbin"
RDCBOOT="${RDCBIN}/sndrboot"
USAGE="Usage: $0 {start|stop} [cluster_resource]"
FLAGFILE=/etc/opt/SUNWesm/donotrun
CLINFO=/usr/sbin/clinfo

killproc() {            # kill the named process(es)
        pid=`/usr/bin/ps -e |
             /usr/bin/grep -w $1 |
             /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
        [ "$pid" != "" ] && kill $pid
}


case "$1" in
'start')
	# presence of $FLAGFILE prevents SVE software fom starting
	if [ -f $FLAGFILE ]
	then
		echo "$0: $FLAGFILE is set: startup aborted"
		exit 0
	fi

	COPT=

	if [ -x ${RDCBOOT} ]
	then
		if ${CLINFO}
		then
			if [ "$2" != "" ]
			then
	 			${RDCBOOT} -r -C $2
			else
				# SNDR 3.2 SetIDs fixup
				${RDCBOOT} -C post-patch-setids -r -s

				COPT="-C l."`/usr/bin/hostname`
				${RDCBOOT} ${COPT} -r
			fi
		else
			# non-clustered start
			${RDCBOOT} -r
		fi
	fi
	;;

'stop')
	COPT=

	if [ ! -r /dev/rdc ]
	then
		RDCBOOT=/usr/bin/true
	fi

	if [ -x ${RDCBOOT} ]
	then
		if ${CLINFO}
		then
			if [ "$2" != "" ]
			then
				${RDCBOOT} -s -C $2
			else
				COPT="-C l."`/usr/bin/hostname`
				${RDCBOOT} ${COPT} -s

				echo "killing SNDR daemons"
				killproc sndrd
				killproc sndrsync
			fi
		else
			# non-clustered stop

			${RDCBOOT} -s

			echo "killing SNDR daemons"
			killproc sndrd
			killproc sndrsync
		fi
	else
		# no sndr boot command, kill daemon anyway

		echo "killing SNDR daemons"
		killproc sndrd
		killproc sndrsync
	fi

	;;

*)
	echo $USAGE
	exit 1
	;;
esac
