NUT

From Gentoo Wiki
Jump to: navigation, search

Do you have a UPS? Do you want to have you system gracefully shutdown in case of a power outage? This guide will show how you can make the most out of your UPS by using NUT from the Network UPS Tools project

Installation

USE flag

If you are connecting your UPS via USB, make sure to set the usb USE flag:

USE flags for sys-power/nut Network-UPS Tools

gui Install NUT-Monitor python gui local
ipmi Support IPMI-based UPSes. local
tcpd Add support for TCP wrappers global
ups_drivers_al175 Driver for Eltek UPS models with AL175 alarm module local
ups_drivers_apcsmart Driver for American Power Conversion Smart Protocol UPS equipment local
ups_drivers_apcsmart-old Driver for American Power Conversion Smart Protocol UPS equipment local
ups_drivers_apcupsd-ups Driver for apcupsd client access local
ups_drivers_bcmxcp Driver for UPSes supporting the serial BCM/XCP protocol local
ups_drivers_bcmxcp_usb Experimental driver for UPSes supporting the BCM/XCP protocol over USB local
ups_drivers_belkin Driver for Belkin serial UPS equipment local
ups_drivers_belkinunv Driver for Belkin "Universal UPS" and compatible local
ups_drivers_bestfcom Driver for Best Power Fortress/Ferrups local
ups_drivers_bestfortress Driver for old Best Fortress UPS equipment local
ups_drivers_bestuferrups Driver for Best Power Micro-Ferrups local
ups_drivers_bestups Driver for Best Power / SOLA (Phoenixtec protocol) UPS equipment local
ups_drivers_blazer_ser Driver for Megatec/Q1 protocol serial based UPS equipment local
ups_drivers_blazer_usb Driver for Megatec/Q1 protocol USB based UPS equipment local
ups_drivers_clone Fake driver to clone outlets for device grouping local
ups_drivers_clone-outlet Fake driver to clone outlets for device grouping local
ups_drivers_dummy-ups Driver for multi-purpose UPS emulation local
ups_drivers_etapro Driver for ETA UPS equipment local
ups_drivers_everups Driver for Ever UPS models local
ups_drivers_gamatronic Driver for Gamatronic UPS equipment local
ups_drivers_genericups Driver for contact-closure UPS equipment local
ups_drivers_isbmex Driver for ISBMEX UPS equipment local
ups_drivers_ivtscd driver for the IVT Solar Controller Device local
ups_drivers_liebert Driver for Liebert contact-closure UPS equipment local
ups_drivers_liebert-esp2 Driver for Liebert UPS, using the ESP-II serial protocol local
ups_drivers_masterguard Driver for Masterguard UPS equipment local
ups_drivers_metasys Driver for Meta System UPS equipment local
ups_drivers_mge-shut Driver for SHUT Protocol UPS equipment local
ups_drivers_mge-utalk Driver for MGE UPS SYSTEMS UTalk protocol equipment local
ups_drivers_microdowell Driver for Microdowell Enterprise UPS series local
ups_drivers_netxml-ups Driver for Eaton / MGE Network Management Card / Proxy (XML/HTTP Protocol) equipment local
ups_drivers_nut-ipmipsu Driver for IPMI Power Supply Units (PSU) local
ups_drivers_nutdrv_qx Driver for Q* protocol serial and USB based UPS equipment local
ups_drivers_oldmge-shut Driver for SHUT Protocol UPS equipment (older implementation) local
ups_drivers_oneac Driver for Oneac UPS equipment local
ups_drivers_optiups Driver for Opti-UPS (Viewsonic) UPS and Zinto D (ONLINE-USV) equipment local
ups_drivers_powercom UPS driver for serial Powercom/Trust/Advice UPS equipment local
ups_drivers_powerpanel Driver for PowerPanel Plus compatible UPS equipment local
ups_drivers_rhino Driver for Brazilian Microsol RHINO UPS equipment local
ups_drivers_richcomm_usb Driver UPS equipment using Richcomm dry-contact to USB solution local
ups_drivers_riello_ser Driver for Riello UPS Protocol UPS equipment local
ups_drivers_riello_usb Driver for Riello UPS Protocol UPS equipment via USB local
ups_drivers_safenet Driver for SafeNet compatible UPS equipment local
ups_drivers_snmp-ups Multi-MIB Driver for SNMP UPS equipment local
ups_drivers_solis Driver for Brazilian Microsol SOLIS UPS equipment local
ups_drivers_tripplite Driver for Tripp-Lite SmartPro UPS equipment local
ups_drivers_tripplite_usb Driver for older Tripp Lite USB UPSes (not PDC HID) local
ups_drivers_tripplitesu Driver for Tripp-Lite SmartOnline (SU) UPS equipment local
ups_drivers_upscode2 Driver for UPScode II compatible UPS equipment local
ups_drivers_usbhid-ups Driver for USB/HID UPS equipment local
ups_drivers_victronups Driver for IMV/Victron UPS unit Match, Match Lite, NetUps local

Emerge

root #emerge --ask sys-power/nut

Configuration standalone

Search a UPS with nut-scanner:

root #/usr/bin/nut-scanner
Scanning USB bus.
Scanning XML/HTTP bus.
No start IP, skipping NUT bus (old connect method)
[nutdev1]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "051D"
        productid = "0002"
        product = "Back-UPS SMC 1500 FW:879.L4 .I USB FW:L4"
        serial = "***"
        vendor = "American Power Conversion"
        bus = "003"

Take note of driver name and port type for configuration file.

If UPS is connected via USB port, add user nut to group usb.

root #usermod -a -G usb nut

Files

/etc/nut/nut.conf

Set mode to standalone if your machine is connected to the UPS directly and you want to run NUT on this machine.

root #nano -w /etc/nut/nut.conf
FILE /etc/nut/nut.confDesired settings
MODE=standalone

/etc/nut/ups.conf

This is where you set up your UPS configuration. Make sure that your UPS name (the text in the brackets) doesn't have any spaces. For configuration specific to your UPS you need to look it up here: NUT Hardware Compatibility Lookup

root #nano -w /etc/nut/ups.conf
FILE /etc/nut/ups.confExample ups.conf configuration
[APCSMC1500]
    driver = usbhid-ups
    port = auto
    desc = "APC SMC1500 UPS"
# Change some variables in UPS hardware. Not all devices or drivers
# implement this, so this may not have effect on your system.
    override.battery.charge.low = 30
    override.battery.runtime.low = 180

/etc/nut/upsd.users

You need to configure at least one user so that upsmon can be launched later. upsd will create a TCP connection that upsmon will use to check on the status of your UPS.

root #nano -w /etc/nut/upsd.users
FILE /etc/nut/upsd.usersExample upsd.users configuration
[monmaster]
    password = mypassword
    upsmon master

/etc/nut/upsmon.conf

Create a MONITOR configuration in /etc/nut/upsmon.conf:

root #nano -w /etc/nut/upsmon.conf
FILE /etc/nut/upsmon.confExample upsmon configuration
MONITOR APCSMC1500@127.0.0.1 1 monmaster mypassword master

# If you want that NUT can shutdown the computer, you need root privileges:
RUN_AS_USER root

MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
NOTIFYCMD /usr/sbin/upssched
POLLFREQ 5
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+EXEC
NOTIFYFLAG NOCOMM	SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT	SYSLOG+WALL

RBWARNTIME 43200

NOCOMMWARNTIME 600

FINALDELAY 5

/etc/nut/upssched.conf

You need to configure operations on that upsmon will check on the status of your UPS.

root #nano -w /etc/nut/upssched.conf
FILE /etc/nut/upssched.confExample upssched.conf configuration
CMDSCRIPT /usr/bin/upssched-cmd
PIPEFN /var/lib/nut/upssched/upssched.pipe
LOCKFN /var/lib/nut/upssched/upssched.lock

AT ONBATT * START-TIMER onbatt 300
AT ONLINE * CANCEL-TIMER onbatt online
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 REPLBATT * EXECUTE replacebatt
root #mkdir -p /var/lib/nut/upssched
root #chown nut:nut /var/lib/nut/upssched

/usr/bin/upssched-cmd

root #nano -w /usr/bin/upssched-cmd
FILE /usr/bin/upssched-cmdExample upssched.conf configuration
#! /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"
                mail -s "The UPS is on battery" admin@example.com
                # For example, uncommenting, you can stop some power-hog services
                #rc-service boinc stop
                #rc-service xmr-stak stop
                ;;
        online)
                logger -t upssched-cmd "The UPS is back on power"
                mail -s "The UPS is back on power" admin@example.com
                # For example, uncommenting, you can restart useful power-hog services
                #rc-service boinc start
                #rc-service xmr-stak start
                ;;
        commbad)
                logger -t upssched-cmd "The server lost communication with UPS"
                mail -s "The server lost communication with UPS" admin@example.com
                ;;
        commok)
                logger -t upssched-cmd "The server re-establish communication with UPS"
                mail -s "The server re-establish communication with UPS" admin@example.com
                ;;
        powerdown)
                logger -t upssched-cmd "The UPS is shutting down the system"
                mail -s "The UPS is shutting down the system" admin@example.com
                ;;
        replacebatt)
                logger -t upssched-cmd "The UPS needs new battery"
                mail -s "The UPS needs new battery" admin@example.com
                ;;
        *)
                logger -t upssched-cmd "Unrecognized command: $1"
                ;;
esac

Services

OpenRC

To add the services to start on system boot:

root #rc-update add upsdrv default
root #rc-update add upsd default
root #rc-update add upsmon default

To start upsd now run:

root #rc-service upsdrv start
root #rc-service upsd start
root #rc-service upsmon start

Check the status of your ups manually. Note that you might have to adjust your UPS name for this work.

root #upsc APCSMC1500@127.0.0.1 ups.status
OL

OL means that your UPS is "online" and not drawing from the battery. It also means that you configured the above files correctly.

If you want nut to power off your UPS when it shuts down your system in a power failure, you must add nut.powerfail to your shutdown runlevel:

root #rc-update add nut.powerfail shutdown

LAN client/server configuration

Server configuration

Starting from standalone configuration, change:

Server files

/etc/nut/nut.conf
root #nano -w /etc/nut/nut.conf
FILE /etc/nut/nut.confDesired settings
MODE=netserver
/etc/nut/upsd.conf
root #nano -w /etc/nut/upsd.conf
FILE /etc/nut/upsd.confDesired settings
LISTEN 127.0.0.1 3493
LISTEN 192.168.1.1 3493
/etc/nut/upsd.users
root #nano -w /etc/nut/upsd.users
FILE /etc/nut/upsd.usersExample upsd.users configuration
[monmaster]
    password = mypassword
    upsmon master

[monslave]
    password = mypassword
    upsmon slave

Client files

/etc/nut/nut.conf
root #nano -w /etc/nut/nut.conf
FILE /etc/nut/nut.confDesired settings
MODE=netclient
/etc/nut/ups.conf

This file is not needed for slave monitor, so you can leave blank or full of comments.

/etc/nut/upsd.conf

This file is not needed for slave monitor, so you can leave blank or full of comments.

/etc/nut/upsd.users
root #nano -w /etc/nut/upsd.users
FILE /etc/nut/upsd.usersExample upsd.users configuration
[monslave]
    password = mypassword
    upsmon slave
/etc/nut/upsmon.conf

Create a MONITOR configuration in /etc/nut/upsmon.conf:

root #nano -w /etc/nut/upsmon.conf
FILE /etc/nut/upsmon.confExample upsmon configuration
MONITOR APCSMC1500@192.168.1.1 1 monslave mypassword slave
/etc/nut/upssched.conf

This file can be the same of standalone configuration.

/usr/bin/upssched-cmd

This file can be the same of standalone configuration.

Client services

On client machine, you need only upsmon service. To add the services to start on system boot:

root #rc-update add upsmon default

To start upsd now run:

root #rc-service upsmon start

Check the status of your ups manually. Note that you might have to adjust your UPS name for this work.

root #upsc APCSMC1500@192.168.1.1 ups.status
OL

External resources