#!/usr/bin/sh
##############################################################################
#  Copyright 2004-2007 Hewlett-Packard Development Company, L.P.  
# Confidential commercial computer software.  Valid license required.
#
# This is the serviceguard in host stop script
##############################################################################
# @(#) $Id$
# Set EXIT to 2 if you wish to try and start the guest on a different member
# Set EXIT to 1 to not try another node
EXIT=1
# Retry counter
RETRYS=0
# Maximum retries
MAX_RETRYS=50
# Sleep interval
INTERVAL=4
# Current state flag
state=Off
# hpvmstart return status
status=0
while true ; do
    state=`/opt/hpvm/bin/hpvmstatus -P ${1} -M | awk -F: '{print $11}'`
    if [[ ${state} = On ]] ; then
	let RETRYS+=1
	if [[ ${RETRYS} -lt ${MAX_RETRYS} ]] ; then
	    sleep ${INTERVAL}
	else
	    echo "Virtual machine already started on this node"
	    exit ${EXIT}
	fi
    else
	/opt/hpvm/bin/hpvmstart -P $1
	status=${?}
	if (( ${status} != 0 )) ; then
	    exit ${EXIT}
	fi
	exit ${status}
    fi 
done
