Monday, February 11, 2013

Shut down ESXi 5.1 guest VMs and the host (free edition) via SSH - the easy way!

Thanks go out to reader Everett for pointing out an easier way to gracefully shutdown guest VMs and the host on a VMware ESXi 5.1 (free) server. 

This is much easier than the method described in the previous post I made on the subject, although that method may have been necessary at the time due to issues with VMware 5.0 U1, or still may be necessary in special cases (clustering, etc.).  The previous method also gives you a tiny bit more control, but it is not supported.

You may want to gracefully shut down your guest VMs and host ESXi 5.1 server via SSH, for example, on the triggering of a UPS power outage event or something similar.

The method is as follows:

1) Install VMware Tools in all guest VMs.

2) Make sure each guest VM is setup to perform the shutdown action "Guest Shutdown" (or you could also use a suspend, if you wanted to) in the virtual host settings "Virtual Machine Startup and Shutdown" section.

3) The following two commands, run in sequence, will shutdown the properly configured guest VMs and the host server also:

/sbin/ && /sbin/poweroff

These commands can be run in sequence via an SSH connection from another system (for example, a batch file and plink on Windows, on a machine running a UPS).  The poweroff will only run if the script runs successfully.

4) That's it!

Thanks Everett!