If you have the power of multiple servers connected to a UPS, you probably need to shut them down when the power goes down and before the UPS runs out of juice. Unless your UPS can be connected to the network, you usually can only connect a single device to it using good old serial or brand new USB. That single host now knows about the UPS status, but what about all the other systems? That’s when Network UPS Tools, aka NUT, comes into play.

NUT comes with a server and a client. You install the server on the device connected to the UPS using serial or USB (or even the network). You install the client on all the other devices.

We will install the server on the Raspberry Pi and the client on the ESXi servers.

Raspberry Pi

I will assume the connection is USB. On the raspberry pi, run the following as root:

apt-get install nut nut-client nut-server
nut-scanner -q -N -U > /etc/nut/ups.conf
echo "LISTEN 3493" > /etc/nut/upsd.conf
MONITOR nutdev1@localhost 1 master s3cr3tp4ssw0rd master

Write the following into /etc/nut/upsd.users:

    password = s3cr3tp4ssw0rd
    actions = SET
    instcmds = ALL
    upsmon master
    password = s3cr3tp4ssw0rd

Restart all services:

systemctl restart nut-driver
systemctl restart nut-server
systemctl restart nut-client
systemctl restart nut-monitor

ESXi hosts

Download the binaries from https://rene.margar.fr/2012/05/client-nut-pour-esxi-5-0/ and copy them to your ESXi host(s).

Configure the host to accept community packages: esxcli software acceptance set –level=CommunitySupported

Extract the file: tar -xzvf NutClient-ESXi-.tar.gz

Install the package: ./upsmon-install.sh

Edit advanced system settings and set the following variables (at least):

  • /UserVars/NutUpsName : nutdev1@raspberrypi-ip-address
  • /UserVars/NutUser : esxi
  • /UserVars/NutPassword : s3cr3tp4ssw0rd

You also need to specify how long the ESXi host will wait before it shuts itself down with the following variable:

  • /UserVars/NutFinalDelay : 5 (default value)

If you want email alert, then configure the following variables as well:

Then, go to the services in the Web UI, edit the startup policy to “start and stop with the host” and start the service immediately.

Validate the setup

On the Raspberry Pi, use tcpdump to capture packets on port 3493, you should see your ESXi hosts talk with the NUT server asking for the UPS status, and the Raspberry Pi answering.

In addition, you should perform a real test by unplugging the power supply of the UPS and check that the ESXi hosts shut themselves down. You will probably want to tune the variable NutFinalDelay based on your UPS capacity and load.