[Nut-upsdev] Shutdown vmware ESX

Svein Skogen (Listmail Account) svein-listmail at stillbilde.net
Tue Dec 22 05:41:11 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charles Lepple wrote:
> On Dec 21, 2009, at 1:13 PM, Svein Skogen (Listmail Account) wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Libor Klepáč wrote:
>>> Hi,
>>> is there some easy way how to shut down vmware ESXi host?
>>> We have same apc smart 1500 and I passed usb port into one virtual
>>> linux, so
>>> it can monitor ups state via NUT.
>>> So how can i make esx server avare of low battery? Maybe using
>>> vsphere-cli
>>> utils?
>>>
>>> With regards
>>> Libor
>>
>> http://communities.vmware.com/docs/DOC-9531
> 
> Svein, thanks for the link.
> 
> Libor, let us know if this for you - this might be something useful to
> add to the NUT documentation.

I used an older variant of that, the one that depends on enabling the
unsupported ssh setup on ESXi myself. Because someone at vmware wisely
decided that those running the free license of ESXi don't need the
ability to actually SEND data to the ESXi host from their VIMa vm.

So what I did, was to set up the ups on a dedicated external machine
(actually an old laptop, since that has its own built in battery), then
allow that laptop to log into the ESXi hosts and start the shutdown
(hence my question some time ago about actually tunning a custom script
for shutdown, not autodetecting the correct one for the local os).

Handling VMWare is a rather special situation, so I'll add a few
reminders for you to help you avoid some of the pitfalls.

- -The vmware guests must be shut down before the host is shut down. Make
sure (especially for FreeBSD guests that default to shutdown-and-hang
they are set up to shutdown-and-poweroff properly. If you need to know
how, I can explain here on the list).

- -If you're running an iSCSI backend for the vmware guests, remember to
make the vmware setup shut down before that iSCSI guest, and power up
the iSCSI backend before the vmware boxes. WOL is your friend for firing
up things in the correct order.

- -If you depend on a network for shutting down/starting up/disks, that
network must have power. Find a nice low powered switch for the job.
Netgear has some nice ones in their pro-safe "smart" range, that has
most of the features a grown man needs, while not draining your battery
or wallet completely.

- -If you use a single machine to shut down stuff in the correct order,
you'll need a little script to verify that things are actually ready to
be powered off on that machine. This is what I use myself:

- -----

#!/bin/sh

echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
# /usr/bin/ssh -i /usr/local/upsmonitor-files/id_rsa.ssh
root at 192.168.4.39 "/ups_shutdown.sh" &

# while /sbin/ping -nc 1 192.168.4.39 > /dev/null
# do
#   echo "Still waiting for ESXi to safely power down"
#   sleep 5
# done

/usr/bin/ssh -i /usr/local/upsmonitor-files/id_rsa.ssh \
	root at castor.stillbilde.net "/ups_shutdown.sh" &

while /sbin/ping -nc 1 192.168.4.40 > /dev/null
do
  echo "Still waiting for castor to safely power down"
  sleep 5
done


/usr/bin/ssh -i /usr/local/upsmonitor-files/id_rsa.ssh \
	root at pollux.stillbilde.net "/ups_shutdown.sh" &
while /sbin/ping -nc 1 192.168.4.41 > /dev/null
do
  echo "Still waiting for pollux to safely power down"
  sleep 5
done

/usr/bin/ssh -i /usr/local/upsmonitor-files/id_rsa_storage \
root at storage.stillbilde.net "/sbin/shutdown -p now" &

while /sbin/ping -nc 1 192.168.4.228 > /dev/null
do
  echo "Still waiting for iSCSI to safely power down"
  sleep 5
done

# /usr/local/bin/upscmd -u admin -p ********* CyberPower at upsmonitor
shutdown.return

- -----

On my setup, the box known as "storage" is set up to deliver iSCSI
services, and is set up to automagically power up when it receives
power. It also has a WOL app that on a schedule checks if "pollux" is
turned on, and if not starts it. The last vm to start on pollux verifies
castor and starts castor. This is because some of the machines on castor
depends on a guest inside pollux (NFS). This method is not pretty, but
at least it actually works. That same vm that starts castor, also
verifies that the upsmonitor machine is switched on, and wakes it. A
crontab job at */2 minutes is your friend here. ;)

The ups_shutdown script found on the vmware communities is this:

- ----
#!/bin/ash
VMID=$(/usr/bin/vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}')

for i in $VMID
do
  STATE=$(/usr/bin/vim-cmd vmsvc/power.getstate $i | tail -1 | awk
'{print $2}')

   if [ $STATE == on ]
   then

       /usr/bin/vim-cmd vmsvc/power.shutdown $i

   fi

done

sleep 60

/sbin/shutdown.sh
/sbin/poweroff
- ----

This last script is most definitely not my work, so I can't really allow
 it into the documentation, but the first script can be included, under
a proper BSD-style license. ;)

//Svein


- --
- --------+-------------------+-------------------------------
  /"\   |Svein Skogen       | svein at d80.iso100.no
  \ /   |Solberg Østli 9    | PGP Key:  0xE5E76831
   X    |2020 Skedsmokorset | svein at jernhuset.no
  / \   |Norway             | PGP Key:  0xCE96CE13
        |                   | svein at stillbilde.net
 ascii  |                   | PGP Key:  0x58CD33B6
 ribbon |System Admin       | svein-listmail at stillbilde.net
Campaign|stillbilde.net     | PGP Key:  0x22D494A4
        +-------------------+-------------------------------
        |msn messenger:     | Mobile Phone: +47 907 03 575
        |svein at jernhuset.no | RIPE handle:    SS16503-RIPE
- --------+-------------------+-------------------------------
         If you really are in a hurry, mail me at
               svein-mobile at stillbilde.net
 This mailbox goes directly to my cellphone and is checked
        even when I'm not in front of my computer.
- ------------------------------------------------------------
                     Picture Gallery:
          https://gallery.stillbilde.net/v/svein/
- ------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkswW/cACgkQODUnwSLUlKRN5wCeIG3wKYih43shZ2+qwVEbOJuq
1QkAn22Wq/6YhhdPOLQQ2VqIlHCoqDVq
=w05P
-----END PGP SIGNATURE-----



More information about the Nut-upsdev mailing list