VM_Helmut
Enthusiast
Enthusiast

Shutdown VMs in regular order using ssh

Jump to solution

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!

0 Kudos
1 Solution

Accepted Solutions
VM_Helmut
Enthusiast
Enthusiast

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

0 Kudos
10 Replies
bsob
Contributor
Contributor

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.

0 Kudos
VM_Helmut
Enthusiast
Enthusiast

I want to use ssh and not the web interface.

0 Kudos
bsob
Contributor
Contributor

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.

0 Kudos
scott28tt
VMware Employee
VMware Employee

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
0 Kudos
VM_Helmut
Enthusiast
Enthusiast

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.

0 Kudos
daphnissov
Immortal
Immortal

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

0 Kudos
VM_Helmut
Enthusiast
Enthusiast

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?

0 Kudos
daphnissov
Immortal
Immortal

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?

0 Kudos
VM_Helmut
Enthusiast
Enthusiast

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

0 Kudos
daphnissov
Immortal
Immortal

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

0 Kudos