Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Freekers/c8e4b75e02bf26e68c4ee6da5a6b2392 to your computer and use it in GitHub Desktop.
Save Freekers/c8e4b75e02bf26e68c4ee6da5a6b2392 to your computer and use it in GitHub Desktop.

Graceful shutdown of UDMP via NUT upon power loss

This documents everything I needed to get my Proxmox instance to listen to my Network UPS Tools (NUT) Server and initiate a shutdown script that would shutdown my UDM Pro upon power loss. This is needed as the UDM Pro does not have the ability to listen to a NUT server on it's own (what the hell ubiquiti).

I'm using a Synology NAS as a NUT server, but you can point your NUT client to any supported UPS. It's set to alert any clients subscribed to it when the UPS connected to it is in low battery. This all applies regardless of what machine you have a NUT server on, it does not have to be Synology.

Additionally these install steps were on my Proxmox machine, but these steps will probably work on any Debian GNU/Linux OS with little to no modification. YMMV

High level summary of the steps:

  • Install the NUT client on Proxmox
  • Enable SSH on the UDM Pro
  • Call shutdown script when NUT Server (i.e. Synology) broadcasts low UPS battery, which will SSH into UDMP and initiate shutdown

Install NUT client on Proxmox Server

With small tweaks I believe most of these steps would work on most linux systems

apt-get install nut sshpass
  • Edit /etc/nut/nut.conf:
MODE=netclient
  • Edit /etc/nut/upsmon.conf: MONITOR <system> <powervalue> <username> <password> ("master"|"slave"):
MONITOR [email protected] 1 monuser secret slave

Replace:

192.168.30.60 → Your NUT Server IP (i.e. Synology)
monuser → Your NUT username, default is 'monuser' for Synology
secret → Your NUT password, default is 'secret' for Synology
  • Start monitoring:
upsmon start
  • To check UPS status: upsc <name> for direct attached units or upsc <name>@<address> for remote

Allow IPs to access NUT Server

This applies to my Synology NAS, I'm not sure if other NUT Servers will require this.

In synology go to Power>UPS Settings, add the IPs of all devices that will be accessing the NUT server. In my case I need to add the IP of my Proxmox instance. Ensure that you're using a static IP.

Enable SSH on UDM Pro

Go to your UniFi OS page select Console Settings. Enable SSH and set a strong and secure password

Set SHUTDOWNCMD in upsmon.conf

On proxmox, update SHUTDOWNCMD in /etc/nut/upsmon.conf

SHUTDOWNCMD "/bin/bash -c 'sshpass -p \"yourpassword\" ssh -o StrictHostKeyChecking=no [email protected] \"ubnt-systool poweroff\" & sleep 3 && /sbin/shutdown -h +0'"

Replace:

yourpassword → Your UDMP root password, which you set earlier above.
192.168.50.1 → Your UniFi Dream Machine Pro's IP.

That's it. Make sure you test and ensure this works on your system. Please feel free to add comments or suggestions.

PS. This is a fork. All credits go to KidA001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment