Prevent OPNsense from shutting down due to UPS shutdown signals (NUT-Tools)

Started by paul_, April 21, 2025, 03:27:51 PM

Previous topic - Next topic
Background:
I am using a UPS that sends a shutdown signal (via the killpower file) to multiple devices, including OPNsense (the firewall). However, I only want my two servers to shut down, not the firewall.

I need a persistent solution that survives reboots and updates, so OPNsense doesn't automatically shut down when the UPS triggers the shutdown event.

Steps Attempted:
Modified /usr/local/etc/nut/upsmon.conf to change the shutdown command (SHUTDOWNCMD) to a custom script that blocks shutdowns based on the presence of the killpower file. Unfortunately, this file gets overwritten on every reboot or NUT service restart.

Created custom scripts to block shutdowns when the killpower file is present, but OPNsense still shuts down immediately when the UPS triggers the shutdown event.

Used the OPNsense Web UI tunables feature to set environment variables for custom shutdown logic, but the changes don't persist or prevent the shutdown.

Modified /usr/local/etc/rc.shutdown to include logic for blocking shutdowns, but the shutdown still happens immediately when the UPS signal is triggered.

Desired Outcome:
OPNsense should NOT shut down when the UPS sends a killpower shutdown signal.

The solution should be persistent and should work across reboots and updates.

The solution should only block shutdowns for OPNsense while allowing the two servers to shut down as normal.


Thanks in advance for your help guys!


Hey that's my reddit post !

Sorry to bring this back from the dead, but I did in fact solve my issue. It was not done in the most elegant way, but it does what I need so, I guess that's good !

My home's setup is a 120v powered Proxmox server (on the UPS) and a 12v powered Proxmox server (on a car battery / home made UPS).

My problem was getting to run NUT server on the 12v Proxmox server OPNsense VM so that it monitors the UPS that is powering the 120v Proxmox server which hosts my primary OPNsense. The 12v OPNsense would always shut down when the 120v UPS would kick in even though it is on a different power source.

The 120v Proxmox server is the main server, which hosts many different VMs and LXC such as my primary OPNsense, FreePBX, Pihole, etc, and the 12v server is the "power outage backup router" that runs the backup OPNsense as well as the Omada controller to keep the APs running, Pihole and others light things, including NUT server.

My not-so-elegant solution :

- I have instealled the NUT server on a Debian VM on the 12v Proxmox server, with a USB passthrough of the port that goes to the UPS
- I have installed the client NUT package ONLY on the primary OPNsense so that it can shut down when there is a power outage, but not on the backup OPNsense.
- I have also created a very basic script that I have added to the crontab. It runs every minute to validate if the UPS is back on power because the "FSD OL" status would always kill my primary OPNsense when it was booting and can only be reset back to "OL" by restarting the daemon.

Here is the cron job script if you are interested. Simply adjust the UPS' name

#!/bin/bash
upsstatus=$(upsc CP1500AVRLCD3@localhost 2>&1 | grep "ups.status:" | sed 's/^.*: //g')

echo "UPS Status : $upsstatus"
if [ "$upsstatus" = "FSD OL" ]; then
#       echo "Restarting NUT daemon"
        /etc/init.d/nut-server restart
else
        echo "Doing nothing"
fi

I understand that this is not a real real solution to running the NUT server on OPNsense, but that is how I ended up doing it.