#!/bin/sh
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)ii	1.17	05/08/09 SMI"

FLAGFILE=/etc/opt/SUNWesm/donotrun
CMD=/usr/opt/SUNWesm/sbin/iiboot
IIADM=/usr/opt/SUNWesm/sbin/iiadm
CLINFO=/usr/sbin/clinfo
hname=`/usr/bin/hostname`

rc=0

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 ${CMD} ]
	then
		if ${CLINFO}
		then
			# in cluster - look for local volumes only
			COPT="-C l.${hname}"
		fi

		${CMD} $COPT -r > /dev/null 2>&1
		rc=$?
	fi
	;;
'stop')
	if [ ! -r /dev/ii ]
	then
		exit 0
	fi

	COPT=

	if [ -x ${CMD} ]
	then
		if ${CLINFO}
		then
			# in cluster - look for local volumes only
			COPT="l.${hname}"
			count=`$IIADM -C -L $COPT | wc -l`
			if [ $count -gt 1 ]
			then
				${CMD} -C $COPT -s
				rc=$?
			fi
		else
			${CMD} -s
			rc=$?
		fi
	fi
	;;
*)
	echo "usage: /etc/init.d/ii {start|stop} "
	exit 1
	;;
esac
exit $rc
