Backup of Network UPS Tools (NUT)
Network UPS Tools (NUT)
My method involves some custom shell scripts to work around the limitations of my UPS model and/or my current understanding of NUT. Though I try my best to implement security best practices here, please use this with caution as you will need to run custom scripts on your validator node.
You will need a UPS with a USB port for this setup.
Plug in your device (node) to the UPS power socket and connect them via a USB cable.
Install the Network UPS Tools package on your device.
sudo apt update
sudo apt install nut nut-client nut-serverInspect the NUT folder.
sudo ls -l /etc/nutYou should see the following configuration files which we will be customising in this guide.
nut.conf ups.conf upsd.conf upsd.users upsmon.conf upssched.confIdentify key information about your UPS.
sudo nut-scannerExample output:
Scanning USB bus.
No start IP, skipping SNMP
Scanning XML/HTTP bus.
No start IP, skipping NUT bus (old connect method)
Scanning IPMI bus.
[nutdev1]
driver = "blazer_usb"
port = "auto"
vendorid = "0665"
productid = "5161"
product = "USB to Serial"
vendor = "INNO TECH"
bus = "003"Back up the exiting ups.conf file as a copy and edit the main file.
Replace the file contents by matching the output from the nut-scanner output above. Use CTRL+T and then CTRL+V to clear all file contents.
Example:
CTRL+O, ENTER, CTRL+X to save and exit.
Back up the exiting upsd.conf file as a copy and edit the main file.
Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents.
CTRL+O, ENTER, CTRL+X to save and exit.
Back up the exiting nut.conf file as a copy and edit the main file.
Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents.
CTRL+O, ENTER, CTRL+X to save and exit.
Back up the exiting upsd.users file as a copy and edit the main file.
Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents.
CTRL+O, ENTER, CTRL+X to save and exit.
Back up the exiting upsmon.conf file as a copy and edit the main file.
Add the following as new lines to the bottom of the existing file content.
And edit the SHUTDOWNCMD line to the following.
CTRL+O, ENTER, CTRL+X to save and exit.
Create the onbatt.sh shell script which tells your device to shut down gracefully when it detects that power supply to your UPS has been cut off (e.g., due to a power outage).
Note: I am using a simple script to handle the automated shutdown sequence because I can't get my NUT to work as intended. Let me know if anyone managed to get yours working.
Paste the following content.
CTRL+O, ENTER, CTRL+X to save and exit.
Make this shell script executable.
Allow the nut user to run only the /sbin/shutdown to power down your device without needing the sudo (superuser) password.
Add the following as a new line in the file.
Restart the NUT services.
Inspect the nut-server and nut-monitor for errors.
Example output:
CTRL+C to exit logging view.
Enable auto-power-on in BIOS
Auto-power-on may not be enabled on your devices by default. If so, you will need to plug in a monitor and keyboard into your device to enable it.
Restart your device and press F2 repeatedly during boot to enter BIOS Setup.
Select
Advanced, then select thePower menu.Expand the
Secondary Power Settingssub-menu and setAfter Power FailuretoPower On.Press F10 to save and exit the BIOS Setup.
Summary of setup
Your device (e.g., validator node) will now gracefully shut down when your UPS is cut off from it's power supply and turn itself back on when power is restored.
If it doesn't (like mine), then you will need to configure a separate Wake-on-LAN (WOL) server to handle automatic power-on signals. Fortunately, this can be done using a $50 Raspberry Pi.
Configure Wake-on-LAN (WOL)
This configuration is applied to any device that needs to be remotely powered on automatically after recovering from a power failure. i.e., the Wake-on-LAN clients
Install wakeonlan and ethtool on your device.
Identify the ethernet interface of your device.
It will be the one that has the 192.168.xx.xx IP address assigned. For example:

Check your existing Wake-on-LAN status. Replace enp2s0with the actual ethernet interface of your device.
If you see the following, you can proceed to the next sub-section. Else, continue following along.
If you see Wake-on: d or any other letter here, it means wake-on-lan is disabled or not optimally configured so you need to change this letter to g.
Next, make this configuration persistent even after rebooting your system.
Add the following lines to your file.
Example of how your file should look like.
CTRL+O, ENTER, CTRL+X to save and exit.
Apply the new configuration.
Enable Wake-on-LAN in BIOS
Wake-on-LAN may not be enabled on your devices by default. If so, you will need to plug in a monitor and keyboard into your device to enable it.
Restart your device and press F2 repeatedly during boot to enter BIOS Setup.
Select
Advanced, then select thePower menu.Expand the
Secondary Power Settingssub-menu and set Wake-on-LAN from S4/S5 to: Power On - Normal Boot.Press F10 to save and exit the BIOS Setup.
Setup an automated Wake-on-LAN server
You will need to use a Raspberry Pi or a similar low-powered device without a standby power mode for this setup. i.e., no on/off button, turns on once connected to a power source.
This device will serve as the Wake-on-LAN server that sends "power on" signals to all your other devices in the same network after recovering from a power failure.
Create a wake-on-LAN script on your Raspberry Pi that covers all your other devices.
Paste the following content:
Add more devices as needed as new lines in the format ["Name"]="MAC Address" within the declare -A devices=(...) segment.
CTRL+O, ENTER, CTRL+X to save and exit.
Make this script executable.
We want this script to run automatically whenever our WOL server restarts after a power failure. Create a new systemd service file to run the script at startup.
Add the following content:
We want the WOL script to run only after all your other devices have completely turned off in the event of a instant recovery following a power failure, which will cause this script to fail its purpose. Hence the deliberate 300 second delay imposed in this service file via /bin/sleep 300
Load and run the WOL service.
Use CTRL+C to exit the monitoring/logging view.
Manual Wake-on-LAN via Telegram Bot
This is useful as a backup to the automated WOL setup above in case you need to manually "wake up" your devices remote after recovery from a power failure.
Key Features:
Does not require opening ports to each of your devices
Conveniently "wakes up" all your devices via Telegram. i.e., without needing to download new apps
Run on your Wake-on-LAN server. e.g., Raspberry Pi that runs 24/7
Requires the "Setup an automated Wake-on-LAN server" sub-section above to be completed
Create a new Telegram bot by following the steps below.
Open Telegram and Message the BotFather:
Search for "BotFather" in Telegram and start a conversation.
Create a New Bot:
Send
/newbotto the BotFather.Follow the instructions in the BotFather chat to name your bot and get its API token.
Save the API Token:
Example token:
123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ.
Add the Bot to Your Private Group:
Invite the bot to your Telegram group.
Get Your Chat ID:
Use the bot to retrieve the chat ID:
Send a message in the Telegram group with your bot
Navigate to
https://api.telegram.org/bot<YourBOTToken>/getUpdateson your browser while replacing<YourBOTToken>with your actual Telegram bot API token
Install dependencies on your WOL server.
Create a new folder to store the bot files.
Create the .env file to store private and sensitive information such as your Telegram bot token and chat ID.
Add your Bot API Token and Chat ID as variables into .env
CTRL+O, ENTER, CTRL+X to save and exit.
Secure the .env file so that only your current user can access the file.
Create the Telegram bot script.
Paste the following content:
CTRL+O, ENTER, CTRL+X to save and exit.
How to use the Telegram Bot: Type /start and then /wol in the chat group created with your bot.
/start: Greets the user and checks if they are authorized./wol: Executes thewake_devicesscript
The Authorization Check ensures only messages from the allowed Chat ID trigger actions.
Make this python file executable.
Create a systemd service file for the bot:
Add the following content:
CTRL+O, ENTER, CTRL+X to save and exit.
Load and run the WOL bot service.
Use CTRL+C to exit the monitoring/logging view.
Last updated