Clean shutdown of Proxmox, VM and LXC in case of blackout: my guide (almost) definitive with NUT and a Tecnoware UPS

Published by TheJoe on

Estimated reading time: 4 minutes

Anyone who runs a homelab sooner or later has to deal with Murphy's law and its most fearsome ally: the sudden blackout.

Under the table in my study there is a faithful Lenovo ThinkCentre M920t with Proxmox VE. Several VMs and several LXCs are running on it: da Home Assistant a Nginx Proxy Manager, via AdGuard, Immich and – above all – a VM with OpenMediaVault (OMV) which manages storage disks in hardware passthrough.

Now, imagine the scene: the power goes out. If the server suddenly shuts down, data file systems become corrupted, the Docker instances inside the containers remain halfway through a write and the Immich database decides to say goodbye forever.

To avoid this tragedy I recovered a UPS Tecnoware Nemo 2.0 equipped with USB port. The goal? When the power goes out, the server must read the UPS battery status and initiate a controlled shutdown procedure, automatic and above all generic.

No abstruse bash scripts with hard-coded passwords that enter each single virtual machine via SSH. Everything must work natively and “the waterfall”.

Here's how I set it all up without even physically touching the server (managing everything via SSH).

1. The theory of “waterfall” (that is to say: how to turn things off properly)

The first thing to understand is that Proxmox and modern operating systems are already designed to handle this situation. When Proxmox receives the order to shut down, sends a signal ACPI to the VMs and a signal lxc-stop ai container.

Note for those who use minimal distributions (this is. Alpine Linux): If among your LXCs you have some lightweight ones based on Alpine Linux (like my FTP server for cams or WUD), you will not find inside systemd but OpenRC. No problem: Proxmox manages lxc-stop in an agnostic way. OpenRC intercepts the stop signal and cleanly stops the services defined in /etc/init.d/ (including the Docker daemon if present), ensuring the correct closure of processes even on distros without systemd.

At that point the systemd inside the VM (o l’LXC) intercepts the signal, warns the Docker daemon, and Docker sends a SIGTERM to containers by closing processes and file systems cleanly.

The only real critical node of my infrastructure is OMV (VM 104): managing storage for many other LXCs, it must be the last resource to turn off and among the first to turn back on.

2. Manage startup and shutdown priorities (Order & Delay)

You don't need a custom script to shut down the VMs in the right order. Proxmox manages the order with the parameter startup.

The logic is simple but fundamental:

  • Starting up: The services with order lower (this is. order=1) they start first.
  • In the process of shutting down: Logic yes reverse! The services with order taller (this is. order=4) they go out first.

Here is the matrix I applied via SSH on Proxmox:

# --- ORDER 1: Rete (DNS & Reverse Proxy) ---
# Si avviano per primi, si spengono per ULTIMI
pct set 101 --startup order=1,up=10,down=10  # AdGuard Home
pct set 102 --startup order=1,up=10,down=10  # Nginx Proxy Manager

# --- ORDER 2: Storage NAS (VM OMV) ---
# Diamo 30s di tempo all'avvio e fino a 60s allo spegnimento per smontare i dischi
qm set 104 --startup order=2,up=30,down=60   # OpenMediaVault

# --- ORDER 3: Servizi Core ---
pct set 109 --startup order=3,up=10,down=15  # Home Assistant
pct set 107 --startup order=3,up=5,down=10   # FTP Cam

# --- ORDER 4: Applicazioni & Media ---
# I primi a spegnersi per bloccare subito le Scritture su OMV
pct set 103 --startup order=4,up=5,down=20   # Immich / Media
pct set 111 --startup order=4,up=5,down=10   # Dashy

And to make sure that when the power returns everything restarts on its own, just enable autostart:

qm set 104 --onboot 1
pct set 101 --onboot 1
# ... e così via per tutti gli altri LXC

(Geek note: remember to enter the BIOS of your PC/Server, in my case the Lenovo M920t, and set the voice After Power Loss its Power On!).

3. Meet NUT and the driver “traitor” from Tecnoware Nemo

We install Proxmox on the host NUT (Network UPS Tools):

apt install nut nut-client nut-server

The donkey often falls here. Many generic tutorials say to use the driver usbhid-ups. However, Tecnoware UPS (like the ERA or NEMO series) under the hood they often use Voltronic/Cypress chipsets on Megatec protocol. If used usbhid-ups, NUT simply will not read the UPS.

Look here:  Temp-throttle: a CLI utility to avoid PC fever

The correct driver for the Tecnoware Nemo 2.0 is nutdrv_qx.

Here is the essential file configuration below /etc/nut/:

1. /etc/nut/nut.conf

MODE=standalone

2. /etc/nut/ups.conf

[nemo]
    driver = nutdrv_qx
    port = auto
    desc = "Tecnoware Nemo 2.0"
    vendorid = "0665"

3. /etc/nut/upsd.users

(Caution: this is NOT a Linux system user, it's just a user internal to the NUT daemon!)

[monuser]
    password = MiaPasswordSegretissima
    upsmon master

4. /etc/nut/upsmon.conf

MONITOR nemo@localhost 1 monuser MiaPasswordSegretissima master
SHUTDOWNCMD "/sbin/shutdown -h +0"

4. The day of the connection (and how to check everything)

As soon as I physically connect the UPS USB cable to the server, the commands to be launched to close the circle will be these:

# 1. Verificare che il controller USB venga visto
lsusb

# 2. Avviare e abilitare i servizi di NUT
systemctl restart nut-server nut-client
systemctl enable nut-server nut-client

# 3. Leggere lo stato della batteria in tempo reale
upsc nemo

HE upsc nemo responds with battery percentage and voltage status… we're done!

What happens now if the power goes out?

  1. The UPS goes on battery and reports the status “Low Battery” a NUT.
  2. NUT issues shutdown command to Proxmox.
  3. Proxmox:
    1. turns off media containers (Order 4)
    2. turns off Home Assistant (Order 3)
    3. shut down the OMV VM by dismounting the volumes safely (Order 2)
    4. turns off DNS and Reverse Proxy (Order 1).
  4. Proxmox shuts down itself and the UPS cuts power.
  5. When the power comes back, the UPS recharges the battery, restores tension to the sockets, the Lenovo BIOS turns the server back on and Proxmox restarts all VMs and LXCs in perfect order.

Zero barbaric scripts to update, zero risk of data corruption, and the awareness that even in the event of a blackout our homelab is in an iron barrel.

And how do you manage the shutdown of your home servers? Let me know in the comments!


TheJoe

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.