VMware Cloud Community
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

Shutdown VMs in regular order using ssh

Hi,

I would like to put the standalone host into maintenance mode and shut down all vms in the regular order (as they would be shutdown if I shutdown / restart the host). What are the preferred commands to do so?

Thank you!

Reply
0 Kudos
1 Solution

Accepted Solutions
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

So I would read the startup order, reverse it and then shutdown each machine? Something like this?

~ # for VM in $(vim-cmd hostsvc/autostartmanager/get_autostartseq | grep -Eo 'vim.VirtualMachine:[0-9]+' | sed 's#vim.VirtualMachine:\([0-9]*\)#\1#g' | sed '1!G;h;$!d'); do echo vim-cmd vmsvc/power.shutdown ${VM}; done

vim-cmd vmsvc/power.shutdown 16

vim-cmd vmsvc/power.shutdown 2

vim-cmd vmsvc/power.shutdown 6

vim-cmd vmsvc/power.shutdown 23

vim-cmd vmsvc/power.shutdown 22

vim-cmd vmsvc/power.shutdown 24

vim-cmd vmsvc/power.shutdown 25

vim-cmd vmsvc/power.shutdown 21

vim-cmd vmsvc/power.shutdown 12

vim-cmd vmsvc/power.shutdown 11

vim-cmd vmsvc/power.shutdown 10

vim-cmd vmsvc/power.shutdown 15

~ #

There is no "simpler" way?

View solution in original post

Reply
0 Kudos
10 Replies
bsob
Contributor
Contributor
Jump to solution

Hi

You can use Virtual Machine Startup and Shutdown order, you can fins these setting on configuration tab esxi host Vcenter or Esxi Web client. Please remeber that if you have HA cluster this setting dosen't work.

Reply
0 Kudos
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

I want to use ssh and not the web interface.

Reply
0 Kudos
bsob
Contributor
Contributor
Jump to solution

You can use ssh to reboot, but shutdown and startup policy you are able to configure using web client, It is not something you can configure using ssh.

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee
Jump to solution

You could always use PowerCLI to carry out this process.


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

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

OK, but what is the command to shutdown the vms? Like

VMware Knowledge Base

but for ALL vms in the order configured in the web client.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

You would have to script which order you wish to shutdown VMs, but you can use vim-cmd for that.

Reply
0 Kudos
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

So I would read the startup order, reverse it and then shutdown each machine? Something like this?

~ # for VM in $(vim-cmd hostsvc/autostartmanager/get_autostartseq | grep -Eo 'vim.VirtualMachine:[0-9]+' | sed 's#vim.VirtualMachine:\([0-9]*\)#\1#g' | sed '1!G;h;$!d'); do echo vim-cmd vmsvc/power.shutdown ${VM}; done

vim-cmd vmsvc/power.shutdown 16

vim-cmd vmsvc/power.shutdown 2

vim-cmd vmsvc/power.shutdown 6

vim-cmd vmsvc/power.shutdown 23

vim-cmd vmsvc/power.shutdown 22

vim-cmd vmsvc/power.shutdown 24

vim-cmd vmsvc/power.shutdown 25

vim-cmd vmsvc/power.shutdown 21

vim-cmd vmsvc/power.shutdown 12

vim-cmd vmsvc/power.shutdown 11

vim-cmd vmsvc/power.shutdown 10

vim-cmd vmsvc/power.shutdown 15

~ #

There is no "simpler" way?

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

If you want simple then you need vCenter Server. You've got a standalone host here with no management capabilities. How much simpler do you want it?

Reply
0 Kudos
VM_Helmut
Enthusiast
Enthusiast
Jump to solution

I just do not want to reinvent the wheel, so if the is a command like

vim-cmd shutdown.all.in.the.reverse.order

I would prefer to use it. Smiley Happy

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Yeah, there's not. You don't get that with free Smiley Happy

Reply
0 Kudos