#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

# define variables

MOUNT=/usr/sbin/mount

validate_options()
{
        debug_message "Function: validate_options - Begin"
	${SET_DEBUG}

        #
        # Ensure all options are set
        #
	rc_validate_options=0

        for i in RESOURCE RESOURCEGROUP PARDIR
        do
                case ${i} in
                        RESOURCE)
                        if [ -z ${RESOURCE} ]; then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                "Function: validate_options - %s Option %s not set" \
                                "${MYNAME}" "-R"
                                rc_validate_options=1
                        fi;;

                        RESOURCEGROUP)
                        if [ -z ${RESOURCEGROUP} ]; then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                "Function: validate_options - %s Option %s not set" \
                                "${MYNAME}" "-G"
                                rc_validate_options=1
                        fi;;

                        PARDIR)
                        if [ -z ${PARDIR} ]; then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                "Function: validate_options - %s Option %s not set" \
                                "${MYNAME}" "-P"
                                rc_validate_options=1
			else
				# construct the variable PARFILE
				PARFILE=${PARDIR}/sczbt_${RESOURCE}
                        fi;;

                esac
        done

	debug_message "Function: validate_options returns ${rc_validate_options} - End"
	return ${rc_validate_options}
}

validate()
{
	#
	# Validate sczbt
	#
	
        debug_message "Function: validate - Begin"
	${SET_DEBUG}

	rc_validate=0

        #
        # Validate that prameter file exists and is syntactically correct
        #

	if ! val_parfile ${PARFILE} "Zonename Zonebootopt Milestone" ${PARDIR}
	then
		debug_message "Function: validate - End"
		rc_validate=1
		return ${rc_validate}
	fi

       # test the semantic of the parameters

       . ${PARFILE}

	for i in `cat ${PARFILE} |grep -v "^#"|grep -v "^ "|nawk -F= '{print $1}'`
        do
                case ${i} in

                        Zonename)
			
			# test the Zonename

			# is the zone name specified

			if [ -z ${Zonename} ]; then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                  "Function: validate - Zone name not set in %s" \
                                  "${PARFILE}"
                		rc_validate=1
			else
				debug_message "Function: validate - Zone name (${Zonename}) set"
			fi

			# is the current zone state valid 

			get_zone_state ${Zonename}

			if [ "${ZONE_STATE}" = "installed" -o "${ZONE_STATE}" = "ready" -o "${ZONE_STATE}" = "running" ]
			then
				debug_message "Function: validate - ${Zonename} state is ${ZONE_STATE}"
			else
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                  "Function: validate - %s state is %s" \
                                  "${Zonename}" "${ZONE_STATE}"
                		rc_validate=1
			fi

			# is the autobooot set to false

			if ! ${ZONECFG} -z ${Zonename} info |grep autoboot|grep false >/dev/null 2>&1
			then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                  "Function: validate - %s configured with autoboot true, it needs to be false" \
                                  "${Zonename}"
                		rc_validate=1
			else
				debug_message "Function: validate - ${Zonename} configured with autoboot false"
                        fi;;

                        Zonebootopt)

			# test the Zones boot options

			# is the Zone boot option specified and a supported one

			if [ ! -z ${Zonebootopt} ] && [ "${Zonebootopt}" != "-s" ]; then

	                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
	                          "Function: validate - %s invalid boot option [%s]" \
	                          "${Zonename}" "${Zonebootopt}"
	                	rc_validate=1
			else
				debug_message "Function: validate - ${Zonename} boot option (${Zonebootopt})"
                        fi;;

                        Milestone)

			# test the smf service which indicate that the zone is online

			# is the Milestone specified

			if [ -z ${Milestone} ]; then
                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                                  "Function: validate - Milestone not set in %s" \
                                  "${PARFILE}"
                		rc_validate=1
			else
				debug_message "Function: validate - Milestone (${Milestone}) set"
			fi;;

		esac
	done

	# validates the Zonepath

	# get the zone path

	get_zonepath ${Zonename}

	# is the Zonepath a directory

	if [ ! -d ${Zonepath} ]; then
                scds_syslog -p daemon.err -t $(syslog_tag) -m \
                "Function: validate - Zonepath %s needs to be a directory" \
                "${Zonepath}" 
                rc_validate=1
	else
		debug_message "Function: validate - Zonepath ${Zonepath} is a directory"
	fi

	# Validate that we are in the global zone

	val_in_global
	if [ ${?} -ne 0 ]; then
		rc_validate=1
	fi 

	# Check if any IPMP_HOST_IP has been configured with the Zone

	LH_LIST=`${SCHA_RESOURCE_GET} -O NETWORK_RESOURCES_USED -R ${RESOURCE} -G ${RESOURCEGROUP}`
	
	for LH in ${LH_LIST}
	do
		get_ipmp_state ${LH}

		# Test if the IPMP_HOST_IP has been configured within the Zone
	
		ZONE_NET_INFO=/tmp/${RESOURCE}_zoneinfo.txt

		echo info net | ${ZONECFG} -z ${Zonename} > ${ZONE_NET_INFO}

		for j in ${IPMP_HOST_IP}
		do
			for i in `grep address ${ZONE_NET_INFO} | awk '{print $2}' | awk -F/ '{print $1}'`
			do
				if [ "${i}" = "${j}" ]
				then
					scds_syslog -p daemon.err -t $(syslog_tag) -m \
       			  	  	  "Function: validate - %s configured with address %s, please remove the address using zonecfg" \
			  	  	  "${Zonename}" "${j}" 
					rc_validate=1
				fi
			done
		done

		# Test if the IPMP_HOST has been configured within the Zone

		for j in ${IPMP_HOST}
		do
			for i in `grep address ${ZONE_NET_INFO} | awk '{print $2}' | awk -F/ '{print $1}'`
			do
				if [ "${i}" = "${j}" ]
				then
					scds_syslog -p daemon.err -t $(syslog_tag) -m \
       			  	  	  "Function: validate - %s configured with address %s, please remove the address using zonecfg" \
			  	  	  "${Zonename}" "${j}" 
					rc_validate=1
				fi
			done
		done

		# Test if another zone is already using this IPMP_HOST_IP

		for ADAPTER in ${ADAPTER_LIST}
		do
			for i in `${IFCONFIG} -a | grep ${ADAPTER} | awk -F: '{print $2}' | grep -v flags`
			do
				IPMP_ADAPTER_IP=`${IFCONFIG} ${ADAPTER}:${i} | grep -w inet | awk '{print $2}'`

				for j in ${IPMP_HOST_IP}
				do
					if [ "${IPMP_ADAPTER_IP}" = "${j}" ]
					then
						if ${IFCONFIG} ${ADAPTER}:${i} | grep -w zone > /dev/null
						then
							ZONE_ADAPTER=`${IFCONFIG} ${ADAPTER}:${i} | grep -w zone | awk '{print $2}'`
	
							scds_syslog -p daemon.err -t $(syslog_tag) -m \
							  "Function: validate - %s (%s) already in use on %s:%s for %s, please resolve this conflict" \
							  "${LH}" "${j}" "${ADAPTER}" "${i}" "${ZONE_ADAPTER}"
							rc_validate=1
						fi
					fi
				done
			done
		done
	done

	# Check Zonebootopt="-s" has Milestone=single-user
	
	if [ "${Zonebootopt}" = "-s" ] 
	then
		if ! echo ${Milestone} | grep single-user > /dev/null
		then
                      	scds_syslog -p daemon.err -t $(syslog_tag) -m \
                      	  "Function: validate - Milestone (%s) is invalid with Zonebootopt=%s, needs single-user" \
                       	  "${Milestone}" "${Zonebootopt}"
               		rc_validate=1
		fi
	fi

	# Check that lofs is not excluded, first check if an exclude lofs in in /etc/system

	if grep -w exclude /etc/system |grep lofs >/dev/null 2>&1
	then
	
	# if yes check if it is commented out

		if ! grep -w exclude /etc/system |grep lofs |egrep "^\*|^ +\*|^#|^ +|	+#|^	+\*" >/dev/null 2>&1
		then
   			scds_syslog -p daemon.err -t $(syslog_tag) -m \
			  "Function: validate - exclude: lofs found in /etc/system" 
			rc_validate=1
		else
			debug_message "Function: validate - exclude: lofs commented out in /etc/system"
		fi
	else
		debug_message "Function: validate - No exclude: lofs found in /etc/system"
	fi

	if [ -n "${Mounts}" ]
	then
		for i in ${Mounts}
		do
			directory=
			localdir=

			if echo ${i} | grep : >/dev/null 2>&1
			then
				echo ${i} | awk -F: '{ print NF,$1,$2 }' | read field_count val1 val2

				case ${field_count} in
					2)	# Support <global zone directory>:<local zone directory>
					  	# Support <global zone directory>:<mount options>
					  	directory=${val1}

						if echo ${val2} | grep / > /dev/null 2>&1
						then
							localdir=${Zonepath}/root${val2}
						else
							localdir=${Zonepath}/root${val1}
						fi
						;;
					3)	# Support <global zone directory>:<local zone directory>:<mount options>
					  	# Support <global zone directory>:<local zone directory>:
						directory=${val1}
						localdir=${Zonepath}/root${val2}
						;;
					*)	scds_syslog -p daemon.err -t $(syslog_tag) -m \
						   "Function: validate - Mounts=%s is invalid" 
						   "${Mounts}"
						rc_validate=1
						;;
				esac
			else
				# Support just <global zone directory> without any further entries
				directory=${i}
				localdir=${Zonepath}/root${i}
			fi

			if [ ! -d ${directory} ]
			then
	   			scds_syslog -p daemon.err -t $(syslog_tag) -m \
				  "Function: validate - Global zones mountpoint %s does not exist" \
				  "${directory}"
				rc_validate=1
			else
				debug_message "Function: validate - mountpoint ${directory} exists in the global zone"
			fi
	
			if [ ! -d ${localdir} ]
			then
	   			scds_syslog -p daemon.err -t $(syslog_tag) -m \
				  "Function: validate - Local zones mountpoint %s does not exist" \
				  "${localdir}"
				rc_validate=1
			else
				debug_message "Function: validate - mountpoint ${localdir} exists in the local zone"
			fi
	
		done
	fi

	debug_message "Function: validate - End"
	return ${rc_validate}
}

lofs_mounts()
{
        debug_message "Function: lofs_mount - Begin"
	${SET_DEBUG}

	# wait until svc:/system/filesystem/minimal:default gets online

	get_svc_state ${Zonename} svc:/system/filesystem/minimal:default

	while [ "${SVC_STATE}" != "online" ]
	do
		debug_message "wait until svc:/system/filesystem/minimal:default gets online in zone ${Zonename}"
		sleep 2
		get_svc_state ${Zonename} svc:/system/filesystem/minimal:default
	done

	# start with the mounts

	get_zonepath ${Zonename}

	for i in ${Mounts}
	do
		source=
		target=
		mountopt=

		if echo ${i} | grep : >/dev/null 2>&1
		then
			echo ${i} | awk -F: '{ print NF,$1,$2,$3 }' | read field_count val1 val2 val3

			case ${field_count} in
				2)	# Support <global zone directory>:<local zone directory>
				  	# Support <global zone directory>:<mount options>
				  	source=${val1}

					if echo ${val2} | grep / > /dev/null 2>&1
					then
						target=${Zonepath}/root${val2}
					else
						target=${Zonepath}/root${val1}
						[ ${val2} ] && mountopt="-o ${val2}"
					fi
					;;
				3)	# Support <global zone directory>:<local zone directory>:<mount options>
				  	# Support <global zone directory>:<local zone directory>:
					source=${val1}
					target=${Zonepath}/root${val2}
					[ ${val3} ] && mountopt="-o ${val3}"
					;;
				*)	scds_syslog -p daemon.err -t $(syslog_tag) -m \
					   "Function: validate - Mounts=%s is invalid" 
					   "${Mounts}"
					;;
			esac
		else
			# Support just <global zone directory> without any further entries
			source=${i}
			target=${Zonepath}/root${i}
		fi

		debug_message "Function: lofs_mounts - will mount ${source} to ${target} with the options ${mountopt}"

		if ${MOUNT} -F lofs ${mountopt} ${source} ${target} >>${LOGFILE} 2>&1
		then 
	   		scds_syslog -p daemon.notice -t $(syslog_tag) -m \
			  "Function: lofsmount - Local zones mount from %s to %s with options %s successful" \
			  "${source}" "${target}" "${mountopt}"
		else
	   		scds_syslog -p daemon.err -t $(syslog_tag) -m \
			  "Function: lofsmount - Local zones mount from %s to %s with options %s unsuccessful" \
			  "${source}" "${target}" "${mountopt}"
		fi
	done
	
        debug_message "Function: lofs_mount - End"
}

get_zonepath()
{
        debug_message "Function: get_zonepath - Begin"
	${SET_DEBUG}

	myzone=${1}
	Zonepath=`${ZONECFG} -z ${myzone} info|grep ^zonepath:|awk '{print $2}'` 


        debug_message "Function: zonepath - End"
}

get_ipmp_hosts()
{
        debug_message "Function: get_ipmp_hosts - Begin"
	${SET_DEBUG}

	LH=$1

	IPMP_HOST=`${SCHA_RESOURCE_GET} -O Extension -R ${LH} -G ${RESOURCEGROUP} HostnameList |tail +2`
	IPMP_HOST_IP=`getent hosts ${IPMP_HOST} | awk '{print $1}'`

        debug_message "Function: get_ipmp_hosts - End"
}

get_ipmp_state()
{
	# Retreive IPMP information for each Network_resources_used entry

        debug_message "Function: get_ipmp_state - Begin"
	${SET_DEBUG}

	LH=$1

	get_ipmp_hosts ${LH}

	NODEID=`${CLINFO} -n`
	
	# Get the correct IPMP group, i.e. <IPMP>@${NODEID}

	IPMP_LIST=`${SCHA_RESOURCE_GET} -O Extension -R ${LH} -G ${RESOURCEGROUP} NetIfList |tail +2`

	for i in ${IPMP_LIST}
	do
		if [ `echo ${i} | awk -F@ '{print $2}'` -eq "${NODEID}" ]
		then
			IPMP_GROUP=`echo ${i} | awk -F@ '{print $1}'`
		fi
	done
		
	# Get the Online IPMP adapter list for that IPMP Group

	LOCALNODENAME=`${SCHA_CLUSTER_GET} -O NODENAME_LOCAL`

	ADAPTER_LIST=`${SCSTAT} -i -h ${LOCALNODENAME} | grep -w ${IPMP_GROUP} | \
		grep Online | awk '{print $6}'`

        debug_message "Function: get_ipmp_state - End"
}


clear_zone()
{
	#
	# kill the processes which are hanging on the file systems and halt the zone
	#

        debug_message "Function: clear_zone - Begin"
	${SET_DEBUG}

	rem_mount=`/sbin/mount | /usr/bin/grep -w ${Zonepath} | /usr/bin/awk '{print $1}'`
	for i in ${rem_mount}
	do
		scds_syslog -p daemon.err -t $(syslog_tag) -m \
       		  "Function: clear_zone - Killing processes with fuser -ck on the file system %s" \
		  "${i}"
		/usr/sbin/fuser -ck ${i}
	done

	sleep 5

	rem_mount=`/sbin/mount | /usr/bin/grep -w ${Zonepath} | /usr/bin/awk '{print $1}'`
	for i in ${rem_mount}
	do

		processes=`/usr/sbin/fuser -c ${i} 2>/dev/null`

		if [ ! -z ${processes} ];then
			scds_syslog -p daemon.err -t $(syslog_tag) -m \
       			  "Function: clear_zone - Killing processes with kill -9 on the file system %s" \
			  "${i}"

			for j in ${processes}
			do
				/usr/bin/kill -9 ${j}
			done
		fi
	done
	
	${ZONEADM} -z ${Zonename} halt >>${LOGFILE} 2>&1

	get_zone_state ${Zonename}

	debug_message "Function: clear_zone - ${Zonename} state is ${ZONE_STATE}"
	debug_message "Function: clear_zone - End"
}

start_sczbt()
{
	#
	# Start sczbt
	#

        debug_message "Function: start_sczbt - Begin"
	${SET_DEBUG}

	# boot the zone

	${ZONEADM} -z ${Zonename} boot ${Zonebootopt}>${LOGFILE} 2>&1

	rc_start_command=${?}

        # disable the pmf tag and run a sleep in the background, to assure, that there will be a valid pmftag during the start phase

        START_TIMEOUT=`${SCHA_RESOURCE_GET} -O START_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}`
        sleep ${START_TIMEOUT} &

        ${PMFADM} -s ${RESOURCEGROUP},${RESOURCE},0.svc

	# mount the requested loopbakcmount to the local zone

	lofs_mounts

	# assign zone flag to registered interfaces of the SUNW.LogicalHostname resources

	if [ "${LH_LIST}" ]
	then
		for LH in ${LH_LIST}
		do
			get_ipmp_state ${LH}

			# Place the IPMP ADAPTER into the local zone

			for ADAPTER in ${ADAPTER_LIST}
			do
				for j in ${IPMP_HOST_IP}
				do
					for i in `${IFCONFIG} -a | grep ${ADAPTER} | awk -F: '{print $2}' | grep -v flags`
					do
						IPMP_ADAPTER_IP=`${IFCONFIG} ${ADAPTER}:${i} | grep -w inet | awk '{print $2}'`
		
						if [ "${IPMP_ADAPTER_IP}" = "${j}" ]
						then
							${IFCONFIG} ${ADAPTER}:${i} zone ${Zonename}
		
		   					scds_syslog -p daemon.notice -t $(syslog_tag) -m \
					  	  	  "Function: start_sczbt - logical interface %s:%s placed into %s" \
						  	  "${ADAPTER}" "${i}" "${Zonename}"
						fi
					done
				done
			done
		done
	fi
		
	debug_message "Function: start_sczbt - End"
	return 0
}

stop_sczbt()
{
	#
	# Stop sczbt
	#

        debug_message "Function: stop_sczbt - Begin"
	${SET_DEBUG}

	# RETRIEVE STOP_TIMEOUT

	STOP_TIMEOUT=`${SCHA_RESOURCE_GET} -O STOP_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}`

	# 60 % OF THE STOP-TIMEOUT CAN BE SPEND ON WAITING

	MAX_STOP_TIMEOUT=`expr ${STOP_TIMEOUT} \* 60 \/ 100`

	# determine if the zoneadmd is running

	ps -z global -o args|grep "zoneadmd -z ${Zonename}$" >/dev/null 2>&1
	admd=${?}

	# bring down the zone

	LH_LIST=`${SCHA_RESOURCE_GET} -O NETWORK_RESOURCES_USED -R ${RESOURCE} -G ${RESOURCEGROUP}`

	if [ "${LH_LIST}" ]
	then
		for LH in ${LH_LIST}
		do
			get_ipmp_state ${LH}

			# Place the IPMP ADAPTER back into the global zone

			for ADAPTER in ${ADAPTER_LIST}
			do
				for j in ${IPMP_HOST_IP}
				do
					for i in `${IFCONFIG} -a | grep ${ADAPTER} | awk -F: '{print $2}' | grep -v flags`
					do
						# For each ${ADAPTER}:${i} check "${IPMP_ADAPTER_IP}" = "${j}" , ${j} is one of the list of ip addresses
						# If there's a match, then for each ${ADAPTER}:${i} check the zone flag = "${Zonename}"
						# If there's a match then place the ${ADAPTER}:${i} back into the global zone
		
						IPMP_ADAPTER_IP=`${IFCONFIG} ${ADAPTER}:${i} | grep -w inet | awk '{print $2}'`
		
						if [ "${IPMP_ADAPTER_IP}" = "${j}" ]
						then
							if ${IFCONFIG} ${ADAPTER}:${i} | grep -w zone > /dev/null
							then
								ZONE_ADAPTER=`${IFCONFIG} ${ADAPTER}:${i} | grep -w zone | awk '{print $2}'`
		
								if [ "${ZONE_ADAPTER}" = "${Zonename}" ]
								then
									${IFCONFIG} ${ADAPTER}:${i} -zone
		
									scds_syslog -p daemon.notice -t $(syslog_tag) -m \
									  "Function: stop_sczbt - Logical interface %s:%s placed into the global zone" \
									  "${ADAPTER}" "${i}"
								fi
							fi
						fi
					done
				done
			done
		done
	fi

	${ZLOGIN} ${Zonename} shutdown -y -g0 -i0 >${LOGFILE} 2>&1

	# run a test loop to determine if the zone is down or the timout is exeeded

	while  [ ${MAX_STOP_TIMEOUT} -ge 5 ]
	do
		
		# check if the zone is offline

		get_zone_state ${Zonename}

		debug_message "Function: stop_sczbt - ${Zonename} state is ${ZONE_STATE}, timeout ${MAX_STOP_TIMEOUT}"

		if [ "${ZONE_STATE}" = "installed" ]; then
		   debug_message "Function: stop_sczbt - ${Zonename} state is ${ZONE_STATE}"
		   MAX_STOP_TIMEOUT=0
		else
		   # reduce MAX_STOP_TIMEOUT and wait 4 seconds
		   MAX_STOP_TIMEOUT=`expr ${MAX_STOP_TIMEOUT} - 6`
		   sleep 4
	
		   if [ ${admd} -ne 0 ]
	           then
			# If a zlogin is impossible leave the loop and start clean_zone. 
			# The zone is "down enough" and will not stop finally

		       if ! ${ZLOGIN} ${Zonename} ls >/dev/null 2>&1
		       then
		           debug_message "Function: stop_sczbt - ${Zonename} no zoneadmd found"
		           MAX_STOP_TIMEOUT=0
		       fi
	           fi

		fi
	done

	# bring the zone down at all costs because the shutdown has exeeded his time limit
	# or got stuck because of the loss of the zoneadmd

	if [ "${ZONE_STATE}" != "installed" ]; then

		# get the zone path

		get_zonepath ${Zonename}

		clear_zone
	fi

        # Send a kill to any pids under the PMFtag

        ${PMFADM} -s ${RESOURCEGROUP},${RESOURCE},0.svc KILL 2> /dev/null
	
	debug_message "Function: stop_sczbt - End"
	return 0
}

check_sczbt()
{
	# 
	# Probe sczbt
	#

        debug_message "Function: check_sczbt - Begin"
	${SET_DEBUG}

	rc_check_sczbt=0

	# check if start program is running

	if  ps -z global -o args |grep start_sczbt |grep -w ${RESOURCE} >/dev/null 2>&1
	then
		debug_message "Function: check_sczbt - Start program is still running "
		rc_check_sczbt=100
		return ${rc_check_sczbt}
	fi

	# do a reduced check as long as the gds_svc_start is running otherwise do an extensive check

	if  ps -z global -o args|grep gds_svc_start|grep -v grep|grep -w ${RESOURCE}>/dev/null 2>&1
	then

		# check if the scheduler is running
	
		if ! pgrep -z ${Zonename} zsched>/dev/null 2>&1
		then
			rc_check_sczbt=100
			debug_message "Function: check_sczbt - Early end"
			return ${rc_check_sczbt}
		fi
	
		# check if zone service is online 
	
		get_svc_state ${Zonename} ${Milestone}

		if [ "${SVC_STATE}" != "online"  -a  "${SVC_STATE}" != "degraded" ]
		then
			rc_check_sczbt=100
			debug_message "Function: check_sczbt - ${Zonename} milestone (${Milestone}) state is ${SVC_STATE}"
			return ${rc_check_sczbt}
		fi
	else

		# check if the scheduler is running
	
		if ! pgrep -z ${Zonename} zsched>/dev/null 2>&1
		then
	             	scds_syslog -p daemon.err -t $(syslog_tag) -m \
	               		"Function: check_sczbt - Zone scheduler for %s not running" \
				"${Zonename}" 
			rc_check_sczbt=100
			debug_message "Function: check_sczbt - Early end"
			return ${rc_check_sczbt}
		fi
	
		# check if the ip addresses of the logical hoists are online
		
		LH_LIST=`${SCHA_RESOURCE_GET} -O NETWORK_RESOURCES_USED -R ${RESOURCE} -G ${RESOURCEGROUP}`

		if [ "${LH_LIST}" ]
		then

			ip_config=`${IFCONFIG} -a`

			for LH in ${LH_LIST}
			do
   				get_ipmp_hosts ${LH}

				for i in ${IPMP_HOST_IP}
				do
					if ! echo ${ip_config} |grep -w ${i}>/dev/null 2>&1
	   				then
		             			scds_syslog -p daemon.err -t $(syslog_tag) -m \
		               				"Function: check_sczbt - Zones %s ip address %s is not running" \
							"${Zonename}" "${i}"
	         				rc_check_sczbt=201
						debug_message "Function: check_sczbt - immediate failover"
						
						return ${rc_check_sczbt}
	   				fi
				done
			done
		fi

		# check if zone service is online if not try for 60 percent of the probe timout

		# RETRIEVE PROBE_TIMEOUT

		PROBE_TIMEOUT=`${SCHA_RESOURCE_GET} -O Extension -R ${RESOURCE} -G ${RESOURCEGROUP} PROBE_TIMEOUT |tail -1`

		# 60 % OF THE START-TIMEOUT CAN BE SPEND ON WAITING

		MAX_PROBE_TIMEOUT=`expr ${PROBE_TIMEOUT} \* 60 \/ 100`

		# test for 60 percent of the probe timeoput if the zone is online

		while [ ${MAX_PROBE_TIMEOUT} -ge 5 ]
		do
			get_svc_state ${Zonename} ${Milestone}
	
			if [ "${SVC_STATE}" != "online" -a "${SVC_STATE}" != "degraded" ]
			then
       		      		scds_syslog -p daemon.err -t $(syslog_tag) -m \
       	        			"Function: check_sczbt - Milestone [%s] not online, try again in 5 seconds" \
					"${Zonename}" "${Milestone}"
				rc_check_sczbt=100
				MAX_PROBE_TIMEOUT=`expr ${MAX_PROBE_TIMEOUT} - 6`
				sleep 4

			else
				MAX_PROBE_TIMEOUT=0
				rc_check_sczbt=0
			fi
	
		done
	fi

	debug_message "Function: check_sczbt - End"
	return ${rc_check_sczbt}
}
