[Linux-HA] status check in resource script for vmware
Jure Pečar
pegasus at nerv.eu.org
Wed May 16 01:15:38 MDT 2007
On Tue, 15 May 2007 10:41:15 +0200
Jure Pečar <pegasus at nerv.eu.org> wrote:
> I have a question about the resource script.
This is what I came up with so far:
#!/bin/bash
# see why this is so at http://www.linux-ha.org/HeartbeatResourceAgent
usage()
{
echo "usage: $0 VMname start|stop|status"
exit 1
}
[ $# -ne 2 ] && usage;
#currently, we plan to have only A and B
if [ "$1" != "A" -a "$1" != "B" ]
then
echo "Invalid VM name (only A or B configured at this point)"
exit 1
fi
#path to VM vmx file
VMPATH="/var/lib/vmware/vm$1/vm$1.vmx"
STATE="`vmware-cmd -q "$VMPATH" getstate`"
HB="`vmware-cmd -q "$VMPATH" getheartbeat`"
case "$2" in
start)
if [ "$STATE" = "off" ]
then
vmware-cmd -q "$VMPATH" start
RETVAL=$?
else
RETVAL=0
fi
;;
stop)
if [ "$STATE" = "on" ]
then
vmware-cmd -q "$VMPATH" stop
RETVAL=$?
if [ $RETVAL -ne 0 ]
then
vmware-cmd -q "$VMPATH" stop hard
RETVAL=$?
fi
else
RETVAL=0
fi
;;
status)
if [ "$STATE" = "on" ]
then
if [ $HB -eq "0" ]
then
echo "OK booting"
else
sleep 5
if [ $HB -lt "`vmware-cmd -q "$VMPATH" getheartbeat`" ]
then
echo "OK running"
else
#query daytime or some other dumb "service"
#have proper hostname in /etc/hosts
if [ -z "`nc -w 5 vm$1 13`" ]
then
echo "seem dead ..."
else
echo "OK but vmware tools not running"
fi
fi
fi
else
echo "stopped or not present"
fi
;;
*)
usage
;;
esac
exit $RETVAL
Any comments?
--
Jure Pečar
http://jure.pecar.org
More information about the Linux-HA
mailing list