VMware Cloud Community
ppsilva02
Contributor
Contributor

Gracefully shutdown ESXi 6.7 with a script via SSH without entering maintenance mode

I'm trying to write a (Python) script that ssh's to an ESXi 6.7 and shuts down the host and also shuts down the VMs according to the current system shutdown policy.

I'm running Dell customized image ESXi 6.7 in a Dell R710 with a dual Xeon X5650 and 144GB RAM and a Dell R720 with a dual Xeon E5-2660.

In fact what I want is the same that I can get with:

Shutdown via GUI

Shut_via_GUI.png

or Shutdown via console

Shut_via_console.png

I have ssh enabled in the server.

I already tryed:

1) host_shutdown.sh (it just gets there indefinitely).

2) /bin/host_shutdown.sh (it to gets there indefinitely).

3) halt (shutdowns the server but it does not shuts down the VMs)

I also tried:

esxcli system shutdown poweroff --reason I_want_IT

but the system must be in maintenance mode and I want to do it without entering maintenance mode.

After digging a lot I found a way to shutdown the hosts:

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

It in fact shuts down the hosts, but I don't know if it is a safe way to.

I really would appreciate some opinion about it.

Kind regards,

Paulo

0 Kudos
2 Replies
Alex_Romeo
Leadership
Leadership

Hi,

This post already solved could help you.

How to shutdown VMs during host poweroff, without using autostart

Best regards,

Alessandro Romeo

Blog: https://www.aleadmin.it/
ppsilva02
Contributor
Contributor

Hi AlessandroRomeo68

First of all, thank you for your help and I'm sorry for the time I took to reply.

In fact I had already seen that article.

But the difference in my scenario is that, as I stated at the beginning of my question, I want to shutdown the VMs accoding to the current system autostart policy ( I'm sorry I wrote "shutdown policy" in the first line.

Meanwhile I found this article: https://daviddever.net/gracefully-stopping-esxi-host-with-usb-ups/  and this one: https://administrator.de/forum/funktioniert-script-esx-msa-shutdown-stromausfall-385489.html (this one is in german but I used Google translator) and this: http://www.designervisuals.com/Shutdown_ESXi_and_VMs_During_a_Power_Failure.html

They are mostly related to shutdown ESXi on UPS power failure, but the result is the same I want to accomplish.

So I'll presume that it will in fact shutdown all machines correctly and will use it in my script

Thank you very much.

0 Kudos