Add a Backup Power Supply
A UPS (uninterruptible power supply) ensures that your node continues to function through minor power fluctuations and power outages.
If you don’t shut your Raspberry Pi down properly this is essentially the same as pulling the power cord out of your desktop computer every time you want to shut it down. When this happens, you risk corrupting your device’s SD card, as well as data on your hard drive.
The solution is that you plug your device into a high-output power bank. This is basically a juiced-up version of what you might use to charge your phone while camping. The battery pack gets plugged into the wall and your device gets plugged into the battery pack.
A UPS should only be relied on to provide you with enough time to safely shut down your node until your power is restored. You should not connect your router or modem to the UPS due to potential data corruption that may occur if your node is in the process of writing to the disk when a power outage occurs.
Many UPS devices have a loud audible alert that will be triggered when the power goes out.
Here are some options to consider:
- https://www.amazon.co.uk/gp/product/B07BZCD927/ For those looking for UK Sockets.
Advanced UPS Setup
If you want to automate a graceful shutdown for the node once the UPS power capacity goes to a minimum level, you can connect the UPS Serial port (via USB) to the Raspberry Pi or PC and have it communicate with the UPS once configuring the UPS daemon in the Pi or you Linux setup correctly, it will initiate a graceful shutdown if the capacity hits 5%
The following steps should be run via SSH:
sudo apt-get install apcupsd sudo nano /etc/default/apcupsd
In /etc/default/apcupsd change ‘ISCONFIGURED=no’ to ‘ISCONFIGURED=yes’
sudo nano /etc/apcupsd/apcupsd.conf
Change the values as below, make sure the DEVICE field is empty, the default is /dev/ttyS0 and should be cleared.
UPSNAME myups UPSCABLE usb UPSTYPE usb DEVICE
Note - Make sure the Restart apcupsd
sudo apcupsd restart
CHECK IF UPS IS RECOGNISED OR ELSE YOU WILL HAVE TO STOP IT!
if this shows
STATUS : COMMLOST
do the following further checks - it could be that UPS is not recognised in USB due to power issue.
will list the connected UBS devices. On some umbrel installations, UPS is not recognised on the USB bus and if that happens you would not see that in the output of this command.
umbrel@umbrel:~ $ lsusb Bus 002 Device 002: ID 2109:0715 VIA Labs, Inc. Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub umbrel@umbrel:~ $
If this happens on your node, there is an issue and you must check /var/log/syslog
tail -f /var/log/syslog
if you see lots of USB related error messages written of the following description
Jul 26 14:30:55 umbrel kernel: [ 6004.122153] usb 1-1: new high-speed USB device number 122 using xhci_hcd Jul 26 14:30:55 umbrel kernel: [ 6004.122286] xhci_hcd 0000:01:00.0: Setup ERROR: setup address command for slot 1. Jul 26 14:30:55 umbrel kernel: [ 6004.330262] xhci_hcd 0000:01:00.0: Setup ERROR: setup address command for slot 1. Jul 26 14:30:55 umbrel kernel: [ 6004.542121] usb 1-1: device not accepting address 122, error -22 Jul 26 14:30:55 umbrel kernel: [ 6004.670139] usb 1-1: new high-speed USB device number 123 using xhci_hcd
you should stop the apcupsd since your device is not recognising the UPS and filling up the syslog with error messages. If you keep it running UPSD which cannot connect to the UBS device, the syslog will be bloated with these error messages. you can press ctrl-c to stop the output from tail -f
sudo /etc/init.d/apcupsd stop
sudo nano /etc/default/apcupsd
In /etc/default/apcupsd change ‘ISCONFIGURED=yes’ to ‘ISCONFIGURED=no’
The implications are that your UPS will protect only for short power outages but would not safely shutdown. We are still looking for solutions for this issue which could be related to the power supply to SSD on some installations.
IF YOUR UPS WAS RECOGNISED and you did not see any issues in syslog as above you are good and proceed below.
Check UPS status:
$ apcaccess status APC : 001,035,0900 DATE : 2021-06-14 02:13:51 +0000 HOSTNAME : umbrelmavic VERSION : 3.14.14 (31 May 2016) debian UPSNAME : myups CABLE : USB Cable DRIVER : USB UPS Driver UPSMODE : Stand Alone STARTTIME: 2021-06-13 01:38:35 +0000 MODEL : Back-UPS ES 350 STATUS : ONLINE LINEV : 120.0 Volts LOADPCT : 0.0 Percent BCHARGE : 100.0 Percent TIMELEFT : 36.4 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds SENSE : High LOTRANS : 88.0 Volts HITRANS : 139.0 Volts ALARMDEL : 30 Seconds BATTV : 13.7 Volts LASTXFER : Unacceptable line voltage changes NUMXFERS : 1 XONBATT : 2021-06-13 01:50:34 +0000 TONBATT : 0 Seconds CUMONBATT: 251 Seconds XOFFBATT : 2021-06-13 01:54:45 +0000 STATFLAG : 0x05000008 SERIALNO : XXXXXXXXXXXX BATTDATE : 2007-06-08 NOMINV : 120 Volts NOMBATTV : 12.0 Volts FIRMWARE : 823.B1.D USB FW:B1 END APC : 2021-06-14 02:13:55 +0000
Once the output looks correct, specifically the STATUS shows as ONLINE, you can test the setup by disconnecting the UPS from the main power, watch the message prompts on the terminal and and let the battery drain until the point that a showdown will be initiated, this will confirm that your setup is correct.
Setting up the UPS with NUT
Network UPS Tools (NUT) supports lots of different UPS types and provides another option of configuring a UPS with a node where the node and the UPS communicate. Working with lots of UPS and generally quite well with Linux it might be a good choice if your UPS is supported.
To see if your UPS is supported visit: https://networkupstools.org/stable-hcl.html
I tested it with a Raspiblitz and an Eaton 3S and it worked perfectly. https://networkupstools.org/
The configuration itself as well as some more advanced features are explained in an easy to follow set of commands here: https://wiki.ipfire.org/addons/nut/detailed
After everything is set up as described you might want to change some parameters to better match the nodes and your personal requirements: In /etc/nut/upsmon.conf one should replace the SHUTDOWNCMD "/sbin/shutdown -h +0" with the suitable command to shut down the node without killing running processes like LND etc. The correct command to shut down a Raspiblitz seems to be "/home/admin/config.scripts/blitz.shutdown.sh" for example. So the line
SHUTDOWNCMD "/sbin/shutdown -h +0"
should be replaced with
in case of a Raspiblitz.
I also wanted to change the behavior once the power is lost. I wanted the node to be powered down much sooner than the default value. So I used the following command to set the value for low battery to 90%. :
upsrw -s battery.charge.low=90 -u admin -p mypasswd
(mypasswd should obviously be replaced with you password) Now the node would be shut down at 90% battery remaining giving it all the time in the world to power off safely.
To view a complete list of the UPS variables, both informational and modifiable (while UPS is the Name of you UPS) use:
To determine the modifiable variables for your UPS, their current settings and their available setting values execute the command:
You can now modify the variables you wish using a command similar to the following:
upsrw -s battery.charge.low=20 -u admin -p admin UPS
Some resources that might help for individual configuration: https://networkupstools.org/docs/user-manual.chunked/ar01s06.html https://wiki.ipfire.org/addons/nut/detailed
To test everything you can plug you laptop into the ups (for draining the battery faster), plug the node not into the USP but some other power source. Then connect the USB-cable of the UPS to the node and disconnect the UPS from external power after that. That way the battery will drain because of the Laptop, it will eventually reach low battery state and execute the shutdown command for the node. At least if you have set everything up correctly...