VMware Cloud Community
danf201110141
Contributor
Contributor

Shutting down via UPS

Hi everyone

I've been experimenting with shutting down my VMs and ESXi remotely.

After some googling and experimenting, I have the following script:

------------------

#!/bin/sh

vim-cmd vmsvc/getallvms  | cut -d' ' -f1 | tail -n +2 | xargs -r -n1 vim-cmd vmsvc/power.suspend
sleep 180

/sbin/shutdown.sh && /sbin/poweroff

----------------

I've tested this and it seems to be working.

One question I do have is is it safe to use `/sbin/shutdown.sh && /sbin/poweroff`. I'm not sure if the scripts are executed in parallel or not. I've tried this on a test host (the script was executed from a machine NOT on the host itself) and it appears to work, but I don't know if I want to risk trying it without getting some feedback. It could be something simple like another sleep command between shutdown and poweroff, but I don't know if this is necessary.

Also, can the script be executed from a virtual machine on the host it's shutting down? (via plink.exe or something similar)

Next week I'll be trying to run it from a virtual machine residing on a host to see if it works, and if it does, I'll slowly start to deploy it.

Thanks,

Dan

Tags (3)
Reply
0 Kudos
4 Replies
mcowger
Immortal
Immortal

The && construct requires that the previous command complete successfully before the next one is run, so they are not parallel.

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
msatya
Enthusiast
Enthusiast

Hi some UPS manufacture like APC providing same software , please check with your UPS manufacture

-------------------------
please award points if you see fit.Thanks

http://imagicon.info/cat/5-59/vbsmile.png

Reply
0 Kudos
danf201110141
Contributor
Contributor

I knew of the '&&' construct from linux. I initially had the shutdown and poweroff separate from each other.

I will install a new Windows test virtual machine today and see if I can use plink to successfully power down the host.

Reply
0 Kudos
danf201110141
Contributor
Contributor

The above script does work.

However, I also discovered that you can get the virtual machines to suspend when the host powers off. I was aware that you could get them to power on with the host, it just never occured to me that a power down was possible as well.

That said, is there any reason to not let ESXi suspend hosts when it powers down? I've tested it on a test host with a couple of test VMs and it appears to be working. All I had to do was execute `/sbin/shutdown.sh && /sbin/poweroff` from my VM with APC Powerchute, and the VMs suspended themselves and powered themselves up automatically at the next start.

The only downside I can think of is forgetting to set a new VM up to auto start/stop - that could cause an issue. Are there any other reasons? Right now if the first command fails to suspend it will try it again during the shutdown script.

Reply
0 Kudos