This is part 2 of my Raspberry Pi as UPS server via the NUT post a while back. I configured my Raspberry Pi to be my NUT server. I have three Cyberpower UPS connected to the RPi via USB cables.
To make a node a NUT client, we need to install the nut-client package.
apt install nut-client
Once the nut-client has been installed, we need to modify some of the NUT configurations. The configuration files are located in
/etc/nut/. The configuration files that require some modification are the following. The description of each configuration is from its man page.
- upsmon.conf – This file’s primary job is to define the systems that upsmon will monitor and to tell it how to shut down the system when necessary. It will contain passwords, so keep it secure. Ideally, only the upsmon process should be able to read it
- nut.conf – This file attempts to standardize the various files being found in different installations
- upssched.conf – This file controls the operations of upssched, the timer-based helper program for upsmon
- upssched-cmd – This script file needs to be created. The script will be called by the upssched
We are going to start with the
upsmon.conf. At this point, adjust the values based on your own environment then paste the configuration to the terminal.
cat > /etc/nut/upsmon.conf << EOF RUN_AS_USER root MONITOR [email protected] 1 username password slave MINSUPPLIES 1 SHUTDOWNCMD "/sbin/shutdown -h" NOTIFYCMD /usr/sbin/upssched POLLFREQ 2 POLLFREQALERT 1 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /etc/killpower NOTIFYMSG ONLINE "UPS %s on line power" NOTIFYMSG ONBATT "UPS %s on battery" NOTIFYMSG LOWBATT "UPS %s battery is low" NOTIFYMSG FSD "UPS %s: forced shutdown in progress" NOTIFYMSG COMMOK "Communications with UPS %s established" NOTIFYMSG COMMBAD "Communications with UPS %s lost" NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding" NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced" NOTIFYMSG NOCOMM "UPS %s is unavailable" NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible" NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL NOTIFYFLAG FSD SYSLOG+WALL+EXEC NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC NOTIFYFLAG NOPARENT SYSLOG+WALL RBWARNTIME 43200 NOCOMMWARNTIME 600 FINALDELAY 5 EOF
We need to set the
nut.conf MODE to nutclient.
echo "MODE=netclient" > /etc/nut/nut.conf
We need to configure the
cat > /etc/nut/upssched.conf << EOF CMDSCRIPT /etc/nut/upssched-cmd PIPEFN /etc/nut/upssched.pipe LOCKFN /etc/nut/upssched.lock AT ONBATT * START-TIMER onbatt 30 AT ONLINE * CANCEL-TIMER onbatt online AT ONBATT * START-TIMER earlyshutdown 30 AT LOWBATT * EXECUTE onbatt AT COMMBAD * START-TIMER commbad 30 AT COMMOK * CANCEL-TIMER commbad commok AT NOCOMM * EXECUTE commbad AT SHUTDOWN * EXECUTE powerdown AT SHUTDOWN * EXECUTE powerdown EOF
We need to create and configure the script and make it executable.
cat > /etc/nut/upssched-cmd << EOF #!/bin/sh case $1 in onbatt) logger -t upssched-cmd "UPS running on battery" ;; earlyshutdown) logger -t upssched-cmd "UPS on battery too long, early shutdown" /usr/sbin/upsmon -c fsd ;; shutdowncritical) logger -t upssched-cmd "UPS on battery critical, forced shutdown" /usr/sbin/upsmon -c fsd ;; upsgone) logger -t upssched-cmd "UPS has been gone too long, can't reach" ;; *) logger -t upssched-cmd "Unrecognized command: $1" ;; esac EOF
chmod 744 /etc/nut/upssched-cmd
Start the nut-client
systemctl restart nut-client
Make sure that you can pull the info using the
upsc [email protected]
Make sure to test the client that it is working. That is it. Cheers!