Tutorials / Shut Down Proxmox Cleanly on a Power Cu…

ProxmoxUPSNUTPower

Shut Down Proxmox Cleanly on a Power Cut with a USB UPS and NUT

Mt
Antony Njagi KigunduCore Mtaalam Technologies

Power cuts are a fact of life in Kenya, and a server that loses power mid-write can corrupt databases, file shares and virtual disks. In this tutorial you will connect a UPS to a Proxmox VE host by USB and configure NUT (Network UPS Tools) so the host shuts every VM down cleanly, then powers itself off, before the battery runs out.

Time: about 45 minutes. Level: intermediate (comfortable with the Linux shell).

Timeline: mains power fails, the UPS switches to battery, NUT sees the battery reach the low threshold, Proxmox shuts down all VMs in order, then the host powers off
What should happen when the power goes. The point is to finish the shutdown with battery to spare.

What you need

  • A UPS with a USB data port (most APC, Eaton and CyberPower models work with NUT's usbhid-ups driver).
  • The USB cable that came with the UPS, connected to the Proxmox host.
  • Root shell access on the Proxmox host (the web console's Shell is fine).

Step 1: Install NUT and find the UPS

apt update
apt install nut
nut-scanner -U

nut-scanner -U lists USB UPS devices it finds, with the driver to use. If nothing shows up, check the cable and run lsusb to confirm the UPS is visible.

Step 2: Configure the UPS driver

Edit /etc/nut/nut.conf and set NUT to standalone mode (the UPS, the server software and the monitor all on this host):

MODE=standalone

Then add the UPS to /etc/nut/ups.conf:

[ups]
    driver = usbhid-ups
    port = auto
    desc = "Server room UPS"

Step 3: Create the monitor user

Add a user to /etc/nut/upsd.users. Use a long random password of your own:

[upsmon]
    password = CHANGE-ME-to-a-long-random-password
    upsmon primary

Then tell the monitor to watch the UPS and how to shut down, in /etc/nut/upsmon.conf:

MONITOR ups@localhost 1 upsmon CHANGE-ME-to-a-long-random-password primary
SHUTDOWNCMD "/sbin/shutdown -h +0"

Protect the files, since they contain the password:

chown root:nut /etc/nut/upsd.users /etc/nut/upsmon.conf
chmod 640 /etc/nut/upsd.users /etc/nut/upsmon.conf

Step 4: Start NUT and read the UPS

Reboot the host, or restart the NUT services, then read the UPS:

upsc ups@localhost

You should see values such as battery.charge, battery.runtime (in seconds) and ups.status. OL means on line (mains power), OB means on battery and LB means low battery.

Step 5: Shut down earlier than the UPS thinks

By default the host shuts down when the UPS reports low battery, which on many units leaves only a minute or two. A Proxmox host with several VMs needs more time than that. Tell the driver to raise the low-battery mark by adding these lines to the [ups] section of /etc/nut/ups.conf:

    ignorelb
    override.battery.charge.low = 50
    override.battery.runtime.low = 600

With these settings the host starts shutting down when the battery falls to 50% or the estimated runtime drops below 10 minutes, whichever comes first. Adjust them to your UPS and load, then restart NUT.

Step 6: Make sure the VMs shut down cleanly

When the host shuts down, Proxmox stops every guest first. To make that clean and orderly:

  • Install the QEMU guest agent in each VM and enable it under the VM's Options → QEMU Guest Agent. Without it, Proxmox relies on ACPI, which Windows can ignore when nobody is logged in.
  • Set the start/shutdown order under Options → Start/Shutdown order. Guests stop in reverse start order, so give application servers a higher order than the database and domain controller they depend on.
  • Set a shutdown timeout that is realistic for slow guests such as database servers.

Step 7: Test it before the power company does

Pick a quiet time and tell users first. Then either unplug the UPS from the wall and watch upsc ups@localhost count down, or force a full shutdown sequence straight away with:

upsmon -c fsd

This really shuts the host and every VM down. Watch that the VMs stop in the order you expect, and time the whole sequence. If it takes longer than the runtime your UPS has left at the threshold, raise the threshold.

Other servers on the same UPS

If a NAS, a second server or a firewall shares the UPS, NUT can serve the UPS status over the network so they shut down too (NUT's netserver mode on the Proxmox host, and a NUT client on the others). Most NAS systems have a built-in NUT client in their UPS settings.

Power protection is point 3 in our 10-point IT checklist for Kenyan SMEs. If you would rather have it done for you, with ordered shutdown across your whole server room and alerts to your phone, get in touch.

Keep building

Want this kind of capability in your business?

Tell us what you are trying to run — we will tell you the honest way to run it. Free consultation, no obligation.

Talk to the team