Is there any way to shutdown a VMware vshere server (Esxi) over ssh. I know Esxi is not really UNIX anymore so shutdown command will not work but the reboot command does seem to work. Is there an equivalent to shutdown?
Thanks
2 Answers
Yes - the 'poweroff' command should work when you are connected via ssh to the ESXi server.
Source:
To make a more complete answer, to do an orderly shutdown, you need to:
- shut down or suspend all running virtual machines(*)
- put the ESXi host in maintenance mode
- shut donw the host
1 - Shutdown or suspend the VMs:
Get the list of VMs with
vim-cmd vmsvc/getallvms
Get the status for each, by using the number from the previous parameter, to check which ones are running and need to be suspended or turned of:
vim-cmd vmsvc/power.getstate #
For those which are powered on:
vim-cmd vmsvc/power.shutdown # or vim-cmd vmsvc/power.suspend #
NOTE: this is to gracefully suspend or shutdown, which depends on VMWare Tools being installed on the OS. This options powers it off directly, for example for VMS without VMWare tools (unless you want to shs them and turn them down by other means):
vim-cmd vmsvc/power.off #
2 - Put host in maintenance mode
esxcli system maintenanceMode set --enable true
This command keeps locked until the host is in maintenance mode. For example, it can wait fro the VMs to finish suspending or shutting down.
3 - Shut down the host
esxcli system shutdown poweroff --reason "A good reason to turn you off!!"
(*) if you're on vCenter, you can also migrate them to a different server