Introduction
Each of my proxmox servers has its own dedicated UPS. My servers are low power and the UPS will keep them up for at least 2 hours. I’m using a Cyberpower UPS connected via USB.
This howto will use a Cyberpower UPS as the example. Its very easy to make a couple changes to use another UPS.
We will be using NUT to do the heavy lifting. When done the server will run and shutdown when the battery reaches 20%. As a bonus notification emails will be sent as well.
Installation and configuration
SSH into your proxmox server with an account that has root privileges.
The only package to install is nut.
>sudo apt install nut
Plug in your UPS to a USB port. We need to find the USB device information for your UPS. So lets list our USB devices.
> lsusb
Here’s my list of USB devices. In this example I’m interested in the Cyberpower. Copy down the ID of your UPS.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub Bus 001 Device 002: ID 0764:0501 Cyber Power System, Inc. CP1500 AVR UPS Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Create the following config file: /etc/nut/ups.conf
maxretry = 3 [theUPS] driver = usbhid-ups port = auto desc = "the server UPS"
We need to create a udev rule to allow nut user access to the driver. The ID you copied down earlier is used here so udev knows which device the rule applies to. So create: /etc/udev/rules.d/90-nut-ups.rules
# Rule for a Cyberpower UPS ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0764", ATTR{idProduct}=="0501", MODE="0660", GROUP="nut"
Now restart udev.
> sudo service udev restart
Next unplug the usb cable to the UPS and plug it back in for the rule to work.
Ok. Its time to configure NUT to run in stand alone mode. Replace /etc/nut/nut.conf with the following:
MODE=standalone
The ups daemon has 2 configuration files to deal with. It needs to be configured for the ip and port to listen on. We also create a user that can monitor the UPS.
Replace /etc/nut/upsd.conf with the following.
# LISTEN <address> [<port>]
LISTEN 127.0.0.1 3493
LISTEN ::1 3493
Replace /etc/nut/upsd.users with the following.
[upsmonitor] password = YOUR_PASSWORD upsmon master
The last file to configure is the UPS monitoring daemon. Replace /etc/nut/upsmon.conf with the following.
# Commands for shutdown on power loss MONITOR theUPS@localhost 1 upsmonitor YOUR_PASSWORD master POWERDOWNFLAG /etc/killpower SHUTDOWNCMD "/sbin/shutdown -h now"
Enable the nut server and client services.
> sudo systemctl enable nut-server.service
> sudo systemctl enable nut-client.service
For the final step lets start the server and client services.
> service nut-server start
> service nut-client start
Conclusion
Nut is a pain to configure, but well worth it.