Shutdown Esxi Server When Running On Battery


I have r720xd installed with esxi 6.7 and vcenter.

I installed. few virtual machines windows linux and a firewall. i bought a ups and connected it to the server with usb. this ups model doesnt have any program or agent for esxi.

i read somewhere that there is a script that i can run to turn off esxi server machine and the vms Operating systems when the Electricity goes down.

Can someone provide step by step how it is done and the script needed?


View Reddit by silentdude2kView Source


To see the full content, share this page by clicking one of the buttons below

Related Articles


  1. You need a network managed UPS. APC has a virtual appliance that will connect to APC network managed UPS units and get notification to trigger VM/Hypervisor shutdown when running on battery.

  2. Am I the only one who finds it odd there’s not better UPS monitoring/shutdown integration in ESXi out of the box?

    I find so many of the available solutions to be kind of kludgey, even if they do work.

  3. I use apcupsd and a shutdown script
    It can detect usb, network or a remote pc with the ups on it.

    It has the username and password coded in and sends it through to esx web command and has worked in a variety of systems

    Try this link https://communities.vmware.com/docs/DOC-33062


    You basically install it on the VM and it detects the power outage and sends a power off to the host which in turn gracefully shutdown the VMs, you have to set that part locally on the esx host but the scripts above look like they do more than I did!

  4. What model UPS do you have? Best way is get something network capable that you can monitor. Many APC models have an expansion slot in the back where you can install network cards.

    There’s also the really ghetto method of spinning up a Linux VM, passing the USB through to it, and installing NUT, though I really don’t recommend this.

    But yeah ESXi doesn’t have the capability to deal with UPSs over USB sadly.

  5. I understand the requirement and was faced with it many times from clients with ROBO setups, but the truth is this is a tough ask. My main sticking issue was always “well, at what % of battery remaining do you want to shutdown ESXi and all guests?” They would say “2 mins remaining” – OK but ESXi and 20 guests may not shut down in 2 minutes. In fact, I could almost promise it wouldn’t. “Well can we shutdown when the UPS goes on battery?” Sure – but then we can expect intermittent power loss to trigger mid-day shutdowns. It’s tough. Also, most environments like this do not have enough battery to run the setup for 60 mins or more… so it’s usually the “2 – 5 minutes remaining” situation. It gets yucky.

  6. Another answer…
    It’s taken me a few days to research how I did it!

    Short answer = windows-vm + apcupsd + vmware-perl-script + serial cable
    The serial port on the vmware host had to be added as a resource for the windows-vm as /dev/char/serial/uart0 & “the special APC UPS Serial cable” (documented in apcupsd docs).

    There are lots of other ways to get comms with the UPS, such as using the network card, but serial works & is cheapest.

    The “vmware special sauce” took the longest to find. I tried using SSH and scripting a shutdown, but it was unreliable.
    Eventually I found a perl repository for vmware, and a script which made it work reliably.
    There’s a whole bunch of scripts here:

    Jolly good luck.

Leave a Reply