#!/usr/bin/ksh
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# SNDR start script
#
# Description:	This is the SNDR switchover script.
#		It is used to start or stop a specified cluster
#		resource group when invoked from the data service cluster
#		failover script.
#
#ident  "@(#)rdc.cluster 1.5     03/03/03 SMI"
#

PATH=/etc:/bin
RDCBIN="/usr/opt/SUNWesm/SUNWrdc/sbin"
RDCLIB="/usr/opt/SUNWrdc/lib"
RDCBOOT="$RDCBIN/sndrboot"
RDCSYNCD="${RDCLIB}/sndrsyncd"
USAGE="Usage: $0 {start|stop} cluster_resource"

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
}

if [[ -z "$2" ]]
then
	echo "$USAGE"
	exit 1
fi

case "$1" in
'start')
	if [[ -x $RDCBOOT ]]
	then
		$RDCBOOT -r -C "$2"
	fi
	## 
	##	Start sndrsyncd
	##

	if [ ! -f ${RDCSYNCD} ]
 	then
 		echo "\nCannot find ${RDCSYNCD}.\nSNDR start aborted."
		exit 1
	fi

	ps -e | grep sndrsyn > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		${RDCSYNCD}
		echo  " sndrsyncd\c"
	else
		echo " sndrsyncd already running\c"
	fi

	;;

'stop')
	killproc sndrsync
	if [[ -x $RDCBOOT ]]
	then
		$RDCBOOT -s -C "$2"
	fi
	;;

*)
	echo $USAGE
	exit 1
	;;
esac
