Difference between revisions of "VMWare Server stop and start via script"
From Noah.org
Jump to navigationJump to searchLine 1: | Line 1: | ||
+ | [[Category:Engineering]] | ||
The "/etc/init.d/vmware stop" command does not work. | The "/etc/init.d/vmware stop" command does not work. | ||
I always get this error: | I always get this error: |
Revision as of 18:33, 27 April 2007
The "/etc/init.d/vmware stop" command does not work. I always get this error:
VMControl error -8: Invalid operation for virtual machine's current state: Make sure the VMware Server Tools are running
So when I want to hard restart a server from a script I end up doing something like this:
BAD_PID=`ps -ef | grep example/Ubuntu.vmx | grep -v grep | awk '{print $2}'` kill -INT $BAD_PID sleep 10 kill -9 $BAD_PID vmware-cmd /var/lib/vmware/Virtual\ Machines/example/Ubuntu.vmx start if [ $? -ne 0 ]; then echo "Example server did not restart." fi
VMWare itself is pretty reliable, but some of my web servers are not. I have a watchdog script similar to the one below that I run from cron. In the real world you might not want to reboot your web server just because it fails to respond to a single query.
#!/bin/sh # This checks that example server is responding to queries. # If it fails then it sends an email alert to a bunch of people. DTS=`date` wget -q --no-cookies -O - http://www.example.com/index.php?q=94105 | grep -q "San Francisco" if [ $? -ne 0 ]; then mail 4155551212@vtext.com noah@example.com -s "ALERT! www.example.com is not responding." <<HERE_ALERT ${DTS} www.example.com did not return expected response to test query. Example server may be down. Trying to hard restart it... HERE_ALERT BAD_PID=`ps -ef | grep example/Ubuntu.vmx | grep -v grep | awk '{print $2}'` kill -INT $BAD_PID sleep 10 kill -9 $BAD_PID vmware-cmd /var/lib/vmware/Virtual\ Machines/example/Ubuntu.vmx start if [ $? -ne 0 ]; then mail 4155551212@vtext.com noah@example -s "ALERT! Example server did not restart." <<HERE_RESTART ${DTS} Example server did not restart. VMWare may be down. HERE_RESTART fi fi