VMware Cloud Community
StefanoChiappin
Contributor
Contributor
Jump to solution

emergency shutdown

Hi,

sometimes I need to perform a fast shutdown of my servers, including ESX. Is there a way to tell all the VMs (either linux, windows or solaris) to shutdown properly, before shutting down ESX servers ? Obviously without logging on each console manually... an automatic procedure would be very appreciated.

Thank you in advanca for any hint,

Stefano

Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

I would add the additional to your script:

#assume worse case the VM might have spaces in the name, this will protect against that

IFS=$'\n'

VMLIST=`vmware-cmd -l`

for config in $ do #vmware-cmd $ stop

#this will try to shutdown the VM properly before initiating a hard shutdown

vmware-cmd "$" trysoft

done

vimsh -n -e /hostsvc/maintenance_mode_enter

shutdown -h now

I had to use the field seperator due to some VMs having spaces/special chracters that threw the traditional "vmware-cmd -l" off, also having the "trysoft" flag is better than just passing in stop which I believe defaults to the "hard" flag, unless you really need to bring them down and don't care about the state of the VM. I would probably also suggest doing a sleep for 3-5seconds in between the shutdown, I think if you shutdown dozen or so, it might error out with some warnings. I've seen that happen when I try to mass suspend 10-12 VMs at a time.

View solution in original post

Reply
0 Kudos
8 Replies
depping
Leadership
Leadership
Jump to solution

you could script this, with vmware-cmd -l you will get a list of all the running vm's, and you can use this as input for vmware-cmd <config> stop:

for instance:

VMLIST=`vmware-cmd -l`

for config in $ do vmware-cmd $ stop

done

shutdown -h now

-


And if you want to you can also have it entering maintenance mode before shutting down, just to be sure: vimsh -n -e /hostsvc/maintenance_mode_enter

Duncan

My virtualisation blog:

bradley4681
Expert
Expert
Jump to solution

The only problem i've found is that initiating a guest shutdown, whether with a script of manually through VC, that windows doesn't always shutdown at all. I've found that having the script run something like pstools or powershell and running the shutdown command on the windows guests remotely and then at the end of the script shutting down the ESX box.

Cheers,

Bradley Sessions

If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

Cheers! If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

I would add the additional to your script:

#assume worse case the VM might have spaces in the name, this will protect against that

IFS=$'\n'

VMLIST=`vmware-cmd -l`

for config in $ do #vmware-cmd $ stop

#this will try to shutdown the VM properly before initiating a hard shutdown

vmware-cmd "$" trysoft

done

vimsh -n -e /hostsvc/maintenance_mode_enter

shutdown -h now

I had to use the field seperator due to some VMs having spaces/special chracters that threw the traditional "vmware-cmd -l" off, also having the "trysoft" flag is better than just passing in stop which I believe defaults to the "hard" flag, unless you really need to bring them down and don't care about the state of the VM. I would probably also suggest doing a sleep for 3-5seconds in between the shutdown, I think if you shutdown dozen or so, it might error out with some warnings. I've seen that happen when I try to mass suspend 10-12 VMs at a time.

Reply
0 Kudos
esiebert7625
Immortal
Immortal
Jump to solution

Here's another thread on this subject...

http://communities.vmware.com/message/667815

Eric Siebert

VMware Communities User Moderator

-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

Check out my website: VMware-land

Read my virtualization blog: SSV Blog

-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

Reply
0 Kudos
williamarrata
Expert
Expert
Jump to solution

I love the scripting, I'm gonna have to try those, thanks for posting the script, anyway, for those who might not be so script happy, the other way to do it is to, from your VC, click the configuration tab, click on the Virtual Machine Startup/Shutdown link, click on the properties, link in the upper right hand corner, here you'll get another window, check the box "Allow virtual machine to Start and stop automatically with the system",

Here is where you configure your environment.start with your startup order, choose your servers to start up first, like DC's or databases, then the rest. Make sure you put them all in Automatic Startup. Then edit your Default startup Delay and Default Shutdown Delay. I 've set mine to 20 seconds for startup and 10 seconds for shutdown. Click OK and your done.

Hope that helped. Smiley Happy

Hope that helped. 🙂
StefanoChiappin
Contributor
Contributor
Jump to solution

Thank you all for the answers.

Just a last question: if I want to suspend the VMs instead of shut them down, how will change the script (and the GUI based procedure) ?

Bye, Stefano

Reply
0 Kudos
esiebert7625
Immortal
Immortal
Jump to solution

Use vmware-cmd suspend instead. Suspending a VM creates a VMSS file for each VM equal in size to the amount of RAM a VM has, the VSWP file is deleted though when a VM is suspended. Be careful using auto-startups, there has been a bug in several versions of ESX 3.x including 3.5 if you use auto startups and restart the hostd service (mgmt-vmware) all your VM's will power down. It has been resolved in several patches.

http://kb.vmware.com/kb/1003312

Eric Siebert

VMware Communities User Moderator

-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

Check out my website: VMware-land

Read my virtualization blog: SSV Blog

-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

Reply
0 Kudos
Tlawry
Contributor
Contributor
Jump to solution

For anyone trying this now the command has been changed since 4.1 from

vmware-cmd -l

to

vim-cmd vmsvc/getallvms

Message was edited by: Tlawry

here is the script reissue for use on 5.0 and up

VMLIST=’vim-cmd vmsvc/getallvms’

for config in ${VMLIST}

do

vim-cmd vmsvc/power.shutdown $config stop trysoft

done

vim-cmd -hostsvc/maintenance_mode_enter

shutdown -h now

Reply
0 Kudos