Designing High-Availability for Xen Virtual Machines with HP Serviceguard for Linux

# An error occured while stopping vm
echo "ERROR: Xen VM shutdown failed"
retval=0 ;;
*)
# xm command failed with an undocumented error
echo "Unrecoverable error occured "
retval=255 ;;
esac
if (( retval != 0 ))
then
echo "ERROR:" $retval " Function sgx_stop_vm"
echo "ERROR:" $retval " Failed to halt xen vm ${SG_XEN_VM_NAME}"
to_exit=1
fi
}
#######################################################################
###
#
# sgx_probe_vm_status() is called to probe the status of a running vm;
# it exits only when the vm is completely halted.
#
# sgx_probe_vm_status is called by sgx_stop_vm to ensure the package is
# completely halted
#
# probe done using the 'xm list' command
#
#######################################################################
###
function sgx_probe_vm_status
{
typeset -i retval=0
typeset -i count=${SG_XEN_PROBE_TIMEOUT}
echo "sgx_probe_vm_status"
if [ -x ${SG_XEN_BIN} ]; then
while [ 1 ]; do
${SG_XEN_BIN} list | grep ${SG_XEN_VM_NAME} | awk '{print $5}' | grep -e "r" -e
"b"
case $? in
0)
# Just wait on the Vm to go down completely
count=count-1
if [ $count -le 0 ]; then
# force power down the VM; this is guaranteed to succeed
echo "WARNING:: Attempting force shutdown of the VM"
${SG_XEN_BIN} destroy ${SG_XEN_VM_NAME}
fi
sleep ${SG_XEN_RETRY_INTERVAL}
continue ;;
1)
20