Skip to content

Instantly share code, notes, and snippets.

@mrflobow
Last active November 13, 2022 07:05
Show Gist options
  • Save mrflobow/28138587097aebdc699d48232dc22ba0 to your computer and use it in GitHub Desktop.
Save mrflobow/28138587097aebdc699d48232dc22ba0 to your computer and use it in GitHub Desktop.
nut-master-guide

NUT Master Node Guide

This guide is base on https://www.youtube.com/watch?v=vyBP7wpN72c.

I used a debian system setup with sudo.

For all steps you need root user priveleges, change to root user (use the matching):

sudo su - 
su -

Install required Software

apt update
apt install nut nut-client nut-server

Scan for devices

nut-scanner -U

Configuration

Make a backup of each config file before proceed e.g. copy ups.conf to ups.example.conf

Add your driver config based on nut-scanner result, in this the ups is referenced as eaton in the further configs. Change this accordingly to your matching name.

ups.conf

pollinterval = 1
maxretry = 3

[eaton]
	driver = "usbhid-ups"
	port = "auto"
	vendorid = "0463"
	productid = "FFFF"
	product = "Ellipse PRO"
	serial = "xxxxx"
	vendor = "EATON"
	bus = "001"

upsmon.conf

RUN_AS_USER nutmon
MONITOR eaton@localhost 1 upsmaster yourpassword1 master

MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
NOTIFYCMD /usr/sbin/upssched
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower

NOTIFYFLAG ONLINE     SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT     SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT    SYSLOG+WALL+EXEC
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 300
FINALDELAY 5

upsd.conf

LISTEN 0.0.0.0 3493

nut.conf

MODE=netserver

upsd.users

[upsmaster]
   password = yourpassword1
   upsmon master

[upsslave]
   password = yourpassword2
   upsmon slave

upssched.conf

CMDSCRIPT /etc/nut/upssched/upssched-cmd
PIPEFN /etc/nut/upssched/upssched.pipe
LOCKFN /etc/nut/upssched/upssched.lock

AT ONBATT * START-TIMER onbatt 30
AT ONLINE * CANCEL-TIMER onbatt online
AT ONBATT * START-TIMER battshutdown 120
AT ONLINE * CANCEL-TIMER battshutdown online
AT LOWBATT * EXECUTE shutdowncritical
AT COMMBAT * START-TIMER commbad 30
AT COMMOK * CANCEL-TIMER commbad commok
AT NOCOMM * EXECUTE commbad
AT SHUTDOWN * EXECUTE powerdown

/etc/nut/upssched/upssched-cmd

#! /bin/sh
#
# This script should be called by upssched via the CMDSCRIPT directive.
#
# Here is a quick example to show how to handle a bunch of possible
# timer names with the help of the case structure.
#
# This script may be replaced with another program without harm.
#
# The first argument passed to your CMDSCRIPT is the name of the timer
# from your AT lines.

case $1 in
	onbatt)
		logger -t upssched-cmd "The UPS is on battery"
		;;
	battshutdown)
		logger -t upssched-cmd "UPS on battery too long, initiate shutdown"
		/sbin/upsmon -c fsd
		;;
	online)
		logger -t upssched-cmd "The UPS is back online"
		;;
	shutdowncritical)
		logger t upssched-cmd "UPS on battery critical, forced shutdown"
		/usr/sbin/upsmon -c fsd
		;;
	upsgone)
		logger -t upssched-cmd "The UPS has been gone for awhile"
		;;
	*)
		logger -t upssched-cmd "Unrecognized command: $1"
		;;
esac

Other steps

useradd -r nutmon
usermod -g nut nutmon
mkdir /etc/nut/upssched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment