This page describes the configuration of an uninterruptible power supply (UPS) for a simple server operating unattended in an electrically unstable region. The configuration has been tested using the openSUSE GNU/Linux distribution.
I have several MGE/Eaton uninterruptible power supply (UPS) units which work well with openSUSE, but this was not an out-of-the-box experience. This page describes the required setup.
There are two basic strategies for stopping a server when building power fails:
Since I live in a region with frequent short power outages, I choose the pessimist strategy, which is implemented in the UPS configuration files described in this page.
The configuration for openSUSE 13.2 described by this page also works for openSUSE 11.2, 11.3 and 12.1. OpenSUSE 12.2 uses version 2.6.3 of NUT, OpenSUSE 12.3 and 13.1 use version 2.6.5. OpenSUSE 13.2, 42.1 and 42.2 use version 2.7.1 of NUT.
When I bought the UPS unit used for this test it was called MGE
(Merlin Gerin) Pulsar Ellipse ASR 1500 USBS
and had reference
number 66781. After the confusing merger of MGE and Eaton and an even
more confusing re-assignment of the two companies' products, the unit
is now known as the Eaton Ellipse ASR 1500 USBS
but mercifully
still has the same reference number 66781. According to Eaton, it has now (2012-04-23)
been replaced by the
Eaton Ellipse ECO 1600 FR USB
.
Four of the eight sockets (the four at the back, visible in figure 1) are battery protected. The four on top, not visible, just have surge protection. A custom cable with an RJ45 connector at the UPS end (not visible in figure 1), plugs into a USB slot in the server. Read a summary of the features.
Read the installation and user manual This document is in 17 languages, its 12.9 Mbyte, but it still doesn't tell you what you need to know when you change the three batteries: to get those four deeply recessed screws out of the side cover, you will need a Torx T10 screwdriver. To remove the bottom plate, you have to remove the screw closest to the power inlet, since the screw goes through part of the bottom plate. The bottom plate is difficult to remove: I have yet to remove the bottom plate from one of these units without breaking at least one of the lugs which clip the bottom plate and the side plate together.
In October 2012, I bought an Eaton Ellipse Max 1500, reference 68557, as shown in figure 2. This unit was formerly known as the Ellipse Max from MGE Office Protection Systems. I had a bad surprize when it arrived. I plugged it in and it made a lot of noise! Unlike the previous version by MGE of this UPS, the current model is slightly longer and is fitted with what must be the noisiest fan available in the whole of the People's Republic of China. You can see the vent in the picture. I see no reason whatsoever why such a UPS should make a noise permanently, even with no load. It's certainly not suitable for office use and I don't recommend it. It went back to the supplier the following day.
This would probably be a good UPS unit if the fan were of better quality and came on only when the unit got hot. In a €300 product it's reasonable to expect Eaton to provide some better quality engineering.
Curiously there is no mention on the Eaton web site or in the product documentation of the noise produced by this unit.
This is a basic product which provides battery backup for four of its eight sockets. the ones at the back. The USB cable supplied is only 1m20 long. I had to replace it with a longer cable for a more comfortable installation. It's good to see UPS manufacturers at last using well known cables.
As with many UPS units, it has two RJ45 sockets to be used to provide power-surge protection for Ethernet or telephone circuits. When used for telephone circuits, special cables will be needed with RJ11/12 plugs at one end and RJ45 plugs at the other. How are these to be wired? Testing shows that a straightforward wiring is incorrect. There is nothing on this subject in the documentation supplied.
2012-04-20 — In file /etc/ups/upssched.conf moved upssched.pipe and upssched.lock from /var/lib/ups/upssched/ to /var/lib/ups/ to avoid creation of new directory.
2012-04-22 — Clarified the use of parameter RUN_AS_USER in files upssched.conf and upsmon.conf.
2012-05-15 — Restricted execution permission to user upsd in files /usr/sbin/upsd, /usr/sbin/upsmon, /usr/sbin/upssched, and upssched-cmd.
2012-09-23 — Updated for 12.2 use of NUT 2.6.3.
2012-10-31 — Added notes on Eaton 68557 and Eco 1600. Added section halt.local.
2013-03-30 — Added note on unexpected empty battery, check for low battery in upssched.conf with action in upssched-cmd. Use meaningful timer names.
2013-08-12 — Updated to cover release 12.3 and to add new systemd service unit for UPS shutdown. Added timers offdelay and ondelay to ups.conf.
2013-09-21 — Added bash script to provide UPS shutdown.
2013-12-09 — Updated for 13.1 use of NUT 2.6.5 and systemd handling of the automatic start of upsd.service.
2015-09-28 — Updated for 13.2 use of NUT 2.7.1. Better names for shutdown script and service. Specify full path in nut-driver.service. Improved trace of SHUTDOWNCMD. Added nut-journal.
2015-10-29 — Added nut-report. Added note on missing +EXEC in upsmon.conf. Added better checking for false low battery reports in upssched-cmd. Added section on setting battery.charge.low.
2015-11-23 — More tuning for false low battery reports in upssched-cmd and upssched.conf. Added low-battery-timer.
2017-04-03 — Added chapter 11 — Heartbeat verification of NUT operation
2019-07-12 — Added direct download of scripts nut-journal and nut-report.
The software used is the GPL version 2 licenced Network UPS Tools (NUT) project version 2.7.1 which is distributed by openSUSE as an RPM package.
The configuration files are to be found in directory /etc/ups/. Certain run-time files are in /var/lib/ups/ and there is a useful script at /usr/sbin/. OpenSUSE releases 12.2, 12.3, 13.1 and 13.2 require either an additional systemd service unit file in /etc/systemd/system/ or a systemd script nut-delayed-ups-shutdown.sh in /usr/lib/systemd/system-shutdown.
Permissions | Owner Group | Name | Purpose | Use |
---|---|---|---|---|
Files provided by NUT | ||||
drwxr-xr-x | root root | /etc/ups/ | Directory | |
-rw-r--r-- | root root | /etc/ups/hosts.conf | CGI programs | Not used |
-rw-r--r-- | root root | /etc/ups/nut.conf | General | |
-rw-r--r-- | root root | /etc/ups/ups.conf | Define UPSs | |
-rw------- | upsd root | /etc/ups/upsd.conf | Access control | Use if no IPv6 |
-rw------- | upsd root | /etc/ups/upsd.users | Network users | |
-rw------- | upsd root | /etc/ups/upsmon.conf | Monitoring | |
-rw-r--r-- | root root | /etc/ups/upssched.conf | Commands | |
-rw-r--r-- | root root | /etc/ups/upsset.conf | Web access | Not used |
drwx------ | upsd daemon | /var/lib/ups/ | Directory | |
-rwxr--r-- | upsd daemon | /usr/sbin/upsd | Binary | |
-rwxr--r-- | upsd daemon | /usr/sbin/upsmon | Binary | |
-rwxr--r-- | upsd daemon | /usr/sbin/upssched | Binary | |
-rwxr-xr-x | root root | /bin/upssched-cmd | Sample script | Not used |
Custom scripts for NUT | ||||
-rwxr--r-- | upsd daemon | /usr/sbin/upssched-cmd | Pessimist strategy script |
|
-rwxr-xr-x | root root | /usr/bin/nut-journal | journalctl helper | |
-rwxr-xr-x | root root | /usr/bin/nut-report | Helper for problem reports |
|
-rw-r--r-- | root root | /etc/ups/heartbeat.dev | dummy-ups script |
Used only by heartbeat |
systemd services required by NUT | ||||
-rw-r--r-- | root root | /usr/lib/systemd/system/nut-driver.service | Calls upsdrvctl | Needs fixing |
-rw-r--r-- | root root | /usr/lib/systemd/system/nut-monitor.service | Calls upsmon | |
-rw-r--r-- | root root | /usr/lib/systemd/system/nut-server.service | Calls upsd | |
-rw-r--r-- | root root | /etc/systemd/system/ nut-delayed-ups-shutdown.service |
systemd service unit |
Choose one of these |
-rwxr--r-- | root root | /usr/lib/systemd/system-shutdown/ nut-delayed-ups-shutdown.sh |
UPS shutdown script |
|
-rwxr-xr-x | root root | /usr/lib/systemd/system-shutdown/ nutshutdown |
openSUSE UPS shutdown script |
Not used |
TCP wrapper files used by NUT | ||||
-rw-r--r-- | root root | /etc/hosts.allow | TCP wrappers access control |
|
-rw-r--r-- | root root | /etc/hosts.deny | TCP wrappers access control |
Not used |
The setup is for a simple configuration with one UPS providing protection for one server. There is no remote access and no web access. If remote access is needed, then the sysadmin has to use SSH to tunnel to the server to which the UPS is attached, and then use the commands available to the local administrator.
Some background : When wall power fails, a UPS unit will shut down a simple desktop PC, and this is sufficient, but shutting down a server is more complex. It must be shut down in such a way that when wall power returns, the server is turned back on again without human intervention.
The technique for doing this relies on a UPS unit which detects that wall power has come back and restarts the server. For this process to work, the UPS unit must receive a delayed-UPS-shutdown signal which will put it into a state where it can detect that wall power has returned and restart the server. A UPS unit which is simply left "beeping" will not restart its load when wall power returns.
It is important to distinguish clearly between the shutdown of the
server, system shutdown
, and the shutdown of the UPS unit.
These are two separate actions. The following table summarises the
techniques I use, but other techniques are possible.
Commanded by | When | ||
---|---|---|---|
Server shutdown |
SHUTDOWNCMD in upsmon.conf e.g. /sbin/shutdown -h +0 |
Decided by time-out in script upssched-cmd |
These two shutdowns race. We want the server to win. |
UPS shutdown |
systemd service unit nut-delayed-ups-shutdown.service e.g. upsdrvctl shutdown |
offdelay seconds after execution of service unit. See ups.conf. |
The UPS delayed shutdown order to be sent to the UPS unit is
not an immediate order. If it were, the UPS would turn off
immediately causing power loss and probable loss of data in the
server. The order used is for a delayed shutdown
, with a
default delay of 20 seconds specified in ups.conf. This may be
sufficient to allow the server to shutdown before the UPS, but there
is no guarantee of this. The UPS and the server race
to
shutdown. We hope the server wins.
Some simple ascii art shows the timing for a 13.1 test rig and the service unit UPS shutdown of chapter 5.13:
systemctl system poweroff halt | |XXXXXXXXXXXXXXXX| 0 2 | 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 secs | | upsdrvctl UPS shutdown shutdown
There is an alternative technique for shutting down the UPS, using a Bash script rather than a systemd service unit. This shortens the race. Some more ascii art shows the timing of the same 13.1 basic test rig and the scripted shutdown of chapter 5.14. The X's show the race window:
systemctl system poweroff halt | |XXXX| 0 2 4 6 8 |10 12 14 16 18 20 22 24 26 28 30 32 secs | | upsdrvctl UPS shutdown shutdown
In the example shown for 13.1, the script solution has the advantage of reducing the race window from 9 to 3 secs. Note that the same security can also be achieved by the service unit by setting offdelay = 26 in ups.conf.
The service unit solution has been considered a really bad
idea
in systemd discussions since it calls upsdrvctl shutdown so
early in the shutdown sequence.
You should chose one or the other of these solutions - not both.
The sample configuration files provided by the NUT project contain detailed descriptions of the use of each file. Hint: make a copy of the /etc/ups directory before making changes. You will find further documentation at /usr/share/doc/packages/nut, and on the NUT project site.
The NUT Developer's Guide includes a very helpful diagram showing how the components of NUT fit together.
The general section of the NUT configuration determines which part of the NUT is to be started.
The standalone mode calls for a local only configuration, with 1 UPS protecting the local system. This implies starting the 3 NUT layers (driver, upsd and upsmon) and the matching configuration files.
# /etc/ups/nut.conf MODE=standalone
13.2: Note that there are no spaces around the "=". This file is intended to be sourced by shell scripts.
Specify and name the UPS which will provide the protection.
As from openSUSE 12.2, the UPS unit poweroff is called for by a
systemd service unit. This is executed early in the shutdown
sequence, and in a slow machine the default 20 seconds before UPS
shutdown may not be enough to allow system shutdown. The usbhid-ups
driver provides options to specify the time intervals before UPS unit
poweroff and poweron. See man usbhid-ups
for details.
As from openSUSE 13.2, an additional delay occurs in the system
shutdown which must be taken into account: The console trace
shows A stop job is running for wicked network management
interfaces (30 sec)
. To avoid the risk of turning off the UPS
before the server stops, I increased the offdelay and ondelay times by
30 seconds.
Where n seconds is the time after the kill power command is sent, and before the UPS is turned off. Default value is 20 seconds.
Where n seconds is the delay for the UPS to switch on in case the power returns after the kill power command had been sent but before the actual switch off. This ensures the machines connected to the UPS are, in all cases, rebooted after a power failure. Default value is 30 seconds. Remember that ondelay must be greater than offdelay.
Here are the values I use:
# /etc/ups/ups.conf # Make sure name matches in /usr/sbin/upssched-cmd and /etc/ups/upsmon.conf [Eaton] driver = usbhid-ups port = auto desc = "Eaton Ellipse ECO 1600" vendorid = 0463 offdelay = 60 ondelay = 70
Specify which ports the upsd daemon will listen on. By default, openSUSE 12.3, 13.1 and 13.2 enable IPv6 so specify:
# /etc/ups/upsd.conf # Make sure this matches the IPv6 setting in YaST => Network Devices => # Network Settings => Global options => IPv6 Protocol Settings # LISTEN <address> [<port>] LISTEN 127.0.0.1 3493 LISTEN ::1 3493
If you disenable IPv6 using YaST => Network Devices => Network Settings => Global options => IPv6 Protocol Settings, then specify only:
# /etc/ups/upsd.conf # LISTEN <address> [<port>] LISTEN 127.0.0.1 3493 # IPv6 turned off
Note: The logic of file upsd.conf is subtle. If no LISTEN addresses are specified in upsd.conf, the compiled in defaults are used. As soon as you specify one or more LISTEN directives, upsd will only listen to the specified addresses.
Thus if both IPv4 and IPv6 LISTEN directives are commented out
# /etc/ups/upsd.conf # LISTEN <address> [<port>] # LISTEN 127.0.0.1 3493 # LISTEN ::1 3493
then NUT listens to 127.0.0.1 and ::1 as shown by /var/log/messages (Pre-13.2) or journalctl (13.2)
Nov 10 09:52:41 glacon2 usbhid-ups[15911]: Startup successful Nov 10 09:52:41 glacon2 upsd[15914]: listening on 127.0.0.1 port 3493 Nov 10 09:52:41 glacon2 upsd[15914]: listening on ::1 port 3493 Nov 10 09:52:41 glacon2 upsd[15914]: Connected to UPS [Eaton]: usbhid-ups-Eaton
But if only ::1 is commented out
# /etc/ups/upsd.conf # LISTEN <address> [<port>] LISTEN 127.0.0.1 3493 # LISTEN ::1 3493
then NUT only listens to 127.0.0.1
Nov 10 09:34:24 glacon usbhid-ups[4282]: Startup successful Nov 10 09:34:24 glacon upsd[4285]: listening on 127.0.0.1 port 3493 Nov 10 09:34:24 glacon upsd[4285]: Connected to UPS [Eaton]: usbhid-ups-Eaton
There are no network users, but we must still define a local user
who has access to the UPS monitoring. This will be needed for the
MONITOR declaration in upsmon.conf The value I use is
# upsd.users [upsmaster] password = sekret upsmon master
You may want something better than sekret
as a password.
By default, upsmon splits into two processes. One stays as root and waits to run the SHUTDOWNCMD. The other one switches to user upsd and does everything else. This file configures these two processes. Here is a summary of the possible entries:
The upsmon instance running as root runs command when the system needs to be shut down. The field command may contain multiple system commands, and we use this to log the action specified by SHUTDOWNCMD.
List the UPSs to be monitored, where
upsmasterwith password
sekret.
mastermeans this system will shutdown last, allowing the slaves time to shutdown first.
slavemeans this system shuts down immediately when power goes critical.
where prog is a program such as /usr/sbin/upssched which will react to the NOTIFY events that have EXEC set with NOTIFYFLAG. See NOTIFYFLAG below for more details.
Where n seconds is the polling interval.
Where n seconds is the polling interval while the UPS is on battery.
Where n seconds is the interval to wait before declaring a stale ups dead
.
The upsmon process will create a file with this name when it's time to shut down the load. See the shutdown.txt file in the docs subdirectory for more information.
Specify messages sent by upsmon when certain events occur. For example
NOTIFYMSG ONLINE "UPS %s on line power"
Where %s is replaced with the identifier of the UPS in question, and message is ascii only, not even ISO Latin1. No accents.
COMMBAD | Communications lost to the UPS |
COMMOK | Communications established with the UPS |
FSD | UPS is being shutdown by the master (FSD = "Forced Shutdown") |
LOWBATT | UPS has a low battery (if also on battery, it's "critical") |
NOCOMM | A UPS is unavailable (can't be contacted for monitoring) |
NOPARENT | The process that shuts down the system has died (shutdown impossible) |
ONBATT | UPS is on battery |
ONLINE | UPS is back online |
REPLBATT | The UPS battery is bad and needs to be replaced |
SHUTDOWN | The system is being shutdown |
By default, upsmon sends walls (global messages to all logged-in users) and writes to the syslog when things happen. You can change this.
notifytype values are listed above.
EXEC | Execute NOTIFYCMD (see above) with the message |
IGNORE | Don't do anything, don't use any other flags on the same line. |
SYSLOG | Write the message in the syslog |
WALL | Write the message to all users on the system |
Where t seconds is the replace battery warning interval.
The monitoring program upsmon will be run as username. For better security, this should not be a regular user, so openSUSE creates the new user upsd in group daemon for this purpose.
In openSUSE, by default, username=upsd and upsd is the owner of file upsmon.conf and directory /var/lib/ups/. I recommend keeping the default openSUSE value.
Where t seconds is the no communications warning time.
Where t seconds is the last sleep interval before shutting down the system.
Here, finally are the values I used:
# /etc/ups/upsmon.conf # Make sure name matches in /usr/sbin/upssched-cmd and /etc/ups/ups.conf MONITOR Eaton@localhost 1 upsmaster sekret master MINSUPPLIES 1 SHUTDOWNCMD "logger -t upsmon.conf \"SHUTDOWNCMD calling /sbin/shutdown to shut down system\" ; /sbin/shutdown -h +0" NOTIFYCMD /usr/sbin/upssched POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /etc/killpower # You can change the default messages to something else if you like. # NOTIFYMSG notifytype "message" # where %s is replaced with the identifier of the UPS in question. NOTIFYMSG COMMBAD "UPS %s: Communications lost +++ Perdu contact avec l'onduleur." NOTIFYMSG COMMOK "UPS %s: Communications (re-)established +++ Onduleur retrouve'." NOTIFYMSG FSD "UPS %s: Forced shutdown in progress +++ Arret obligatoire en cours." NOTIFYMSG LOWBATT "UPS %s: Battery is low +++ Batterie se vide." NOTIFYMSG NOCOMM "UPS %s: Not available +++ Onduleur indisponible." NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible." NOTIFYMSG ONBATT "UPS %s: On battery +++ Onduleur sur batterie." NOTIFYMSG ONLINE "UPS %s: On line power +++ Onduleur sur secteur." NOTIFYMSG REPLBATT "UPS %s: Battery needs to be replaced +++ Batterie d'onduleur a` remplacer." NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding +++ Arret automatique en cours." NOTIFYFLAG COMMBAD SYSLOG+EXEC NOTIFYFLAG COMMOK SYSLOG+EXEC NOTIFYFLAG FSD SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5
This file specifies the timer actions associated with the UPS events. It works in close cooperation with the script upssched-cmd.
Where the script scriptname gets called to invoke commands for timers that trigger. It is given a single argument - the timername in your AT ... START-TIMER definitions.
This must be defined *before* the first AT line. Otherwise the program will complain and exit without doing anything.
This sets the file name of the FIFO that will pass communications between processes to start and stop timers. This should be set to some path where normal users can't create the file, due to the possibility of symlinking and other evil.
Note: by default, upsmon will run upssched as whatever user you have defined with RUN_AS_USER in upsmon.conf. Make sure that user can create files and write to files in the path you use for PIPEFN and LOCKFN. My recommendation: stay with the user upsd defined by openSUSE, and place PIPEFUN in directory /var/lib/ups/ owned by upsd.
Required Declaration. upssched needs to be able to create this filename in order to avoid a race condition when two events are dispatched from upsmon at nearly the same time. This file will only exist briefly. It must not be created by any other process.
You should put this in the same directory as PIPEFN.
Define a handler for a specific event notifytype on UPS upsname. upsname can be the special value * to apply this handler to every possible value of upsname.
Run the command command via your CMDSCRIPT when it happens. Note: Any AT that matches both the notifytype and the upsname for the current event will be used.
Possible values for command
Declare and start a timer called timername that will trigger after interval seconds, calling your CMDSCRIPT with timername as the first argument.
Example: Start a timer that will execute when any UPS (*) has been gone 10 seconds
AT COMMBAD * START-TIMER upsgone 10
Cancel a running timer called timername, if possible. If the timer has passed then pass the optional argument [cmd] to CMDSCRIPT.
Example: If a specific UPS (myups@localhost) comes back online, then stop the timer before it triggers
AT COMMOK myups@localhost CANCEL-TIMER upsgone
Immediately pass command as an argument to CMDSCRIPT.
Example: If any UPS (*) reverts to utility power, then execute 'ups-back-on-line' via CMDSCRIPT.
AT ONLINE * EXECUTE ups-back-on-line
Here, finally, are the values I used for this configuration file:
# /etc/ups/upssched.conf # See also /usr/sbin/upssched-cmd CMDSCRIPT /usr/sbin/upssched-cmd PIPEFN /var/lib/ups/upssched.pipe LOCKFN /var/lib/ups/upssched.lock # Define timer to give two minute warning AT ONBATT * START-TIMER two-minute-warning-timer 5 # Define timer to give one minute warning AT ONBATT * START-TIMER one-minute-warning-timer 65 # Define timer to shut down box AT ONBATT * START-TIMER shutdown-timer 125 ## Alternative timer definitions for a faster shutdown #AT ONBATT * START-TIMER one-minute-warning-timer 5 #AT ONBATT * START-TIMER shutdown-timer 65 # Turn off timers if power comes back AT ONLINE * CANCEL-TIMER two-minute-warning-timer AT ONLINE * CANCEL-TIMER one-minute-warning-timer AT ONLINE * CANCEL-TIMER shutdown-timer AT ONLINE * EXECUTE ups-back-on-line # Defective UPS runs down on its own for no reason! AT LOWBATT * START-TIMER low-battery-timer 5 AT LOWBATT * START-TIMER shutdown-timer 65
upssched-cmd is a script for handling timer completion and other events. It works in close cooperation with the configuration file upssched.conf which specifies the timers. NUT provides a script /bin/upssched-cmd which is minimal and is not used in the configuration described here.
The script provided here is adapted from a complete script supplied
by MGE with the UPS when I bought it. The MGE script addressed
the optimist
strategy described in the
Introduction but the
version given here implements the pessimist
strategy.
I placed this script in the directory /usr/sbin to emphasize its nature. It's not an executable for the ordinary user. Although it isn't a binary file, it shouldn't be in /bin.
#!/bin/bash -u # /usr/sbin/upssched-cmd # Adapted from code supplied by MGE. # See also /etc/ups/upssched.conf # &1 is the name of the timer which has just expired # Debugging: Log all calls to this script logger -i -t upssched-cmd Calling upssched-cmd $1 # Make sure this corresponds to declaration in /etc/ups/ups.conf UPS="Eaton@localhost" # What is the current battery charge? CHARGE=`upsc $UPS battery.charge` if [[ $? -ne 0 ]] then logger -i -t upssched-cmd "Configuration error: unable to read charge of UPS $UPS" fi LOW=`upsc $UPS battery.charge.low` STATUS=`upsc $UPS ups.status` CHMSG="$STATUS $CHARGE%" # Messages to be put in front of the users MSG0="Power back, $CHMSG - shutdown cancelled. +++ Secteur de retour - arret abandonne." MSG2="Running on battery, $CHMSG - possible shutdown in 2 minutes - save your work! +++ Sur batterie - arret possible en 2 minutes - sauvez votre travail!" MSG3="Running on battery, $CHMSG - probable shutdown in 1 minute - save your work now! +++ Sur batterie - arret en 1 minute - sauvez votre travail maintenant!" # On low battery, turn off box in 30 seconds # Check that timer value matches AT LOWBATT * START-TIMER shutdown-timer MSG4="Low battery, $CHMSG - probable shutdown in 30 secs - save your work now! +++ Batterie dechargee - arret en 30 sec - sauvez votre travail maintenant!" # Where does openSUSE hide stuff? sbinPath="/usr/sbin/" # The basic strategy is: Do not shutdown based on battery runtime # or charge since the "quick shutdown" strategy does not rely on # measuring the battery charge. All shutdowns are based on elapsed time. # However experience shows that some UPS units mysteriously # loose their charge for no apparent reason. In this case, we # assume an emergency situation and in upssched.conf we call for # a quick shutdown using the timers "low-battery-timer" and "shutdown-timer". case $1 in # Handle warning timers two-minute-warning-timer) logger -i -t upssched-cmd "Two minute warning timeout reached, $CHMSG" echo $MSG2 | wall ;; one-minute-warning-timer) logger -i -t upssched-cmd "One minute warning timeout reached, $CHMSG" echo $MSG3 | wall ;; # Handle shutdown timer. When triggered, # timer has expired, so immediately shutdown. shutdown-timer) logger -i -t upssched-cmd "Shutdown timer reached: Calling upsmon -c fsd, $CHMSG" ${sbinPath}upsmon -c fsd ;; ups-back-on-line) logger -i -t upssched-cmd "ups_back-on-line: removing timers, $CHMSG" echo $MSG0 | wall ;; # Defective UPS signals low charge for no reason. # Note: to change the default low battery charge to say 36: # upsrw -s battery.charge.low=36 -u upsmaster -p sekret my-ups low-battery-timer) logger -i -t upssched-cmd "$MSG4" echo $MSG4 | wall ;; *) logger -i -t upssched-cmd "Unrecognized command: \"$1\", $CHMSG" ;; esac
NUT uses TCP-Wrappers to provide controlled access to the daemon upsd. Access control is applied to NUT clients specified in upsd.users. The TCP-Wrappers support is optional in NUT but is included in the openSUSE 12.3, 13.1 and 13.2 packaging of NUT. NUT works directly with TCP-Wrappers and does not require the super-daemon inetd, which is not used by openSUSE 12.3, 13.1 or 13.2.
Unfortunately this non-use of inetd means that the very useful wrapper test programs tcpdchk and tcpdmatch which assume that the inetd daemon is present are not available to test your configuration.
See man tcpd
, man -S5 hosts_access
and man -S5
hosts_options
for a detailed description of /etc/hosts.allow and
/etc/hosts.deny. These last two man pages have been removed from 13.2.
Try the Internet or an earlier distribution.
As from 13.2 TCP-Wrappers are being abandoned, but the package is
still loaded. See the OpenSUSE forum discussion of TCP Wrappers as abandonware
.
The two files hosts.allow and hosts.deny provide a powerful means of controlling access, providing precision of access control not available with firewalls. The mechanism is based on rules for what is allowed and what is to be denied. In my simple configuration I explicitly state for each rule whether it is an ALLOW rule or a DENY rule, and I place all the rules in the file hosts.allow. I have no hosts.deny file; since I rename the example provided by SuSE.
The rules have two forms, basic and debugging:
where
localhost, LOCAL, 127.0.0.1, [::1]
Note that the IPv6 address of the local host is placed in square brackets.
where
localhost, LOCAL, 127.0.0.1, [::1]
spawn (/bin/mail -r hosts.allow@localhost\ -s '%s@%h (bigserver) refused access to %d from %c'\ sysadmin@localhost) &
Where you replace bigserver
and sysadmin
by your own values.
If the TCP-Wrappers access control rejects the access to upsd, you will receive an e-mail with a subject line such as "upsd@::1 (glacon2) refused access to upsd from upsmaster@::1". I got this message because I forgot to include [::1] in the client_list.
Finally, here are the relevant parts of my /etc/hosts.allow
# /etc/hosts.allow # 2010-10-03 Roger Price # Notes: # 1. See `man tcpd', `man -S5 hosts_access' and `man -S5 hosts_options' # for a detailed description of /etc/hosts.allow and /etc/hosts.deny. # 2. This file contains both the authorisations and the denials. # The option ALLOW or DENY is explicit on each rule. # 3. The file hosts.deny is no longer used. ... upsd : localhost, LOCAL, 127.0.0.1, [::1] : ALLOW upsd : ALL : spawn (/bin/mail -r hosts.allow@localhost\ -s '%s@%h (glacon2) refused access to %d from %c'\ roger@localhost) & : DENY ... # And now the denials which previously appeared in /etc/hosts.deny # ALL : ALL : DENY
See man tcpd
, man -S5 hosts_access
for a detailed
description of hosts.allow and hosts.deny. See
also man -S5 hosts_options
for additional options to the rules.
This file is not used and is not present in my configuration. All denials are specified in hosts.allow.
Like the alien plant in the
Quatermass Experiment, systemd is spreading throughout
openSUSE. In 13.2, the NUT server, monitor and driver become systemd
service units. These are defined by openSUSE and are not a part of
the NUT source code. In /usr/lib/systemd/system we now find
the power devices information server
:
[Unit] Description=Network UPS Tools - power devices information server After=local-fs.target network.target nut-driver.service Requires=nut-driver.service Before=nut-monitor.service [Service] ExecStart=/usr/sbin/upsd Type=forking [Install] WantedBy=multi-user.target
You can get the status of this service at any time:
pinta:~ # systemctl status nut-server.service nut-server.service - Network UPS Tools - power devices information server Loaded: loaded (/usr/lib/systemd/system/nut-server.service; enabled) Active: active (running) since Sun 2015-10-04 22:12:32 CEST; 11h ago Process: 1717 ExecStart=/usr/sbin/upsd (code=exited, status=0/SUCCESS) Main PID: 1718 (upsd) CGroup: /system.slice/nut-server.service └─1718 /usr/sbin/upsd Oct 04 22:12:32 pinta upsd[1718]: Startup successful Oct 04 22:12:32 pinta upsd[1718]: User upsmaster@127.0.0.1 logged into UPS [Eaton] Oct 04 22:12:32 pinta upsd[1717]: fopen /var/lib/ups/upsd.pid: No such file or directory Oct 04 22:12:32 pinta upsd[1717]: listening on 127.0.0.1 port 3493 Oct 04 22:12:32 pinta upsd[1717]: Connected to UPS [Eaton]: usbhid-ups-Eaton
The service needs to be enabled using Yast => System => Services Manager. Once enabled, it will be started automatically at each power-on by systemd.
It is also possible to stop and start the service at any time using the commands rcupsd stop and rcupsd start but this is deprecated by openSUSE.
In 13.2 openSUSE also defines the power devices monitor and
shutdown controller
. This is not a part of the NUT source code.
In /usr/lib/systemd/system we now find:
[Unit] Description=Network UPS Tools - power device monitor and shutdown controller After=local-fs.target network.target nut-server.service [Service] ExecStart=/usr/sbin/upsmon PIDFile=/var/run/upsmon.pid Type=forking [Install] WantedBy=multi-user.target
You can get the status of this service at any time:
pinta:~ # systemctl status nut-monitor.service nut-monitor.service - Network UPS Tools - power device monitor and shutdown controller Loaded: loaded (/usr/lib/systemd/system/nut-monitor.service; enabled) Active: active (running) since Sun 2015-10-04 22:12:32 CEST; 12h ago Process: 1719 ExecStart=/usr/sbin/upsmon (code=exited, status=0/SUCCESS) Main PID: 1721 (upsmon) CGroup: /system.slice/nut-monitor.service ├─1720 /usr/sbin/upsmon └─1721 /usr/sbin/upsmon Oct 04 22:12:32 pinta upsmon[1720]: Startup successful Oct 04 22:12:32 pinta upsmon[1719]: fopen /var/run/upsmon.pid: No such file or directory Oct 04 22:12:32 pinta upsmon[1719]: UPS: Eaton@localhost (master) (power value 1) Oct 04 22:12:32 pinta upsmon[1719]: Using power down flag file /etc/killpower
The service needs to be enabled using Yast => System => Services Manager. Once enabled, it will be started automatically at each power-on by systemd. Note that there are two instances of upsmon running, one owned by root to execute SHUTDOWNCMD, the other owned by upsd to do the rest of the work.
In 13.2 openSUSE also defines the power device driver
controller
. This is not a part of the NUT source code. In
/usr/lib/systemd/system we now find:
[Unit] Description=Network UPS Tools - power device driver controller After=local-fs.target network.target StopWhenUnneeded=yes [Service] ExecStart=/upsdrvctl start ExecStop=/upsdrvctl stop Type=forking
This service unit is broken, the ExecStart and ExecStop lines should read:
# Make explicit that upsdrvctl is in /usr/lib/ups/driver/ ExecStart=/usr/lib/ups/driver/upsdrvctl start ExecStop=/usr/lib/ups/driver/upsdrvctl stop
You will have to make this change yourself. Once repaired, you can get the status of this service at any time:
pinta:~ # systemctl status nut-driver.service nut-driver.service - Network UPS Tools - power device driver controller Loaded: loaded (/usr/lib/systemd/system/nut-driver.service; static) Active: active (running) since Sun 2015-10-04 22:12:32 CEST; 12h ago Process: 1493 ExecStart=/usr/lib/ups/driver/upsdrvctl start (code=exited, status=0/SUCCESS) Main PID: 1716 (usbhid-ups) CGroup: /system.slice/nut-driver.service └─1716 /usr/lib/ups/driver/usbhid-ups -a Eaton Oct 04 22:12:30 pinta upsdrvctl[1493]: Using subdriver: MGE HID 1.32 Oct 04 22:12:30 pinta upsdrvctl[1493]: Network UPS Tools - Generic HID driver 0.38 (2.7.1) Oct 04 22:12:30 pinta upsdrvctl[1493]: USB communication driver 0.32 Oct 04 22:12:32 pinta usbhid-ups[1716]: Startup successful Oct 04 22:12:32 pinta upsdrvctl[1493]: Network UPS Tools - UPS driver controller 2.7.1
You do not need to enable this service.
This systemd service unit calls for a delayed UPS shutdown. The delay is specified by ups.conf This systemd service is not a part of NUT and is not provided by openSUSE. You have to create it yourself. The unit is the new file /etc/systemd/system/nut-delayed-ups-shutdown.service :
# nut-delayed-ups-shutdown.service # OpenSUSE 12.3, 13.1, 13.2 powerdown: server shutdown requires UPS shutdown # This service fixes a problem with openSUSE 12.3, 13.1, 13.2 NUT. # Background: When wall power fails the system and the UPS must # be shut down in such a way that when wall power returns, # the server is turned back on again without human intervention. # For this process to work, the UPS unit must receive a # delayed-UPS-shutdown signal which will put it into a state where # it will restart the server when wall power returns. A UPS unit # which is simply left beeping will not restart its load when wall # power returns. [Unit] Description=Initiate delayed UPS shutdown Before=umount.target DefaultDependencies=no [Service] Type=oneshot ExecStart=/usr/bin/logger -t upsdrvctl "nut-delayed-ups-shutdown.service calling upsdrvctl to shut down UPS unit" ExecStart=/usr/lib/ups/driver/upsdrvctl shutdown [Install] WantedBy=final.target
The service needs to be enabled using Yast => System => Services Manager. Once enabled, it will be started automatically by systemd at each system shutdown. To enable the service pre-13.2, use command
pinta:~ # systemctl --system reenable /etc/systemd/system/nut-delayed-ups-shutdown.service ln -s '/etc/systemd/system/nut-delayed-ups-shutdown.service' '/etc/systemd/system/final.target.wants/nut-delayed-ups-shutdown.service'
It's status is normally:
pinta:~ # systemctl status nut-delayed-ups-shutdown.service nut-delayed-ups-shutdown.service - Initiate delayed UPS shutdown Loaded: loaded (/etc/systemd/system/nut-delayed-ups-shutdown.service; enabled) Active: inactive (dead)
There is an alternative to this service; a Bash script described in the next chapter. For a discussion of the two techniques, and the race involved, see Setup and the Race.
This alternative technique for delayed shutdown of the UPS uses a Bash script. As with the service, the delay is specified by ups.conf. You either use the service or the script, one or the other, not both.
systemd provides drop-in
directories for scripts which
should be executed as late as possible during a system shutdown.
/usr/lib/systemd/system-shutdown is for a user's scripts, and
/lib/systemd/system-shutdown is for system scripts. Although
shutting down a UPS unit is clearly a system matter and not a user
matter, I use the /usr/lib/... directory since my script is not
part of an officially distributed product.
openSUSE 13.2 provides a delayed shutdown script for NUT in /usr/lib/systemd/system-shutdown/nutshutdown . I have not tested and do not use this script which I have commented out.
systemd detects automatically that a script in one of
these drop-in
directories needs to be executed. There is no
need to enable the script.
Place the following script nut-delayed-ups-shutdown.sh in /usr/lib/systemd/system-shutdown : Note: in openSUSE release 12.2 there is no /usr/lib... so you have to choose /lib/...
#! /bin/bash # nut-delayed-ups-shutdown.sh Delayed turn off for the UPS unit. # Needed for automatic system restart when wall power returns. UPSDRVCTL_BIN=/usr/lib/ups/driver/upsdrvctl $UPSDRVCTL_BIN shutdown
There is no need to enable the script and no trace in /var/log/messages or journalctl of the action of this script. The only evidence is that the UPS shuts down. For a further discussion of the two shutdown techniques, and the race involved, see Setup and the Race.
Extracting the NUT activity logged by journald can be laborious since the information is diluted by all the other activity that gets logged. This Bash helper script picks out the journald entries generated by NUT activity during the previous complete boot through shutdown sequence, and the current boot. This script is not a part of NUT or openSUSE. I placed it in directory /usr/bin/ . You can download the script directly from here.
The best way to file a report about the use of NUT is in the Nut-upsuser mailing list. If you wish to show your current configuration, then I suggest you use the utility script nut-report to prepare a condensed display of your configuration. This script is not a part of NUT or openSUSE. I placed it in directory /usr/bin/ . You can download the script directly from here.
For a complete report, run the script as user root. The script creates a file /tmp/NUT.report with a summary of your NUT configuration. Passwords have been removed. To submit this report to the Nut-upsuser mailing list, either place it on a web server if you have access to one, or upload the file to a free file hoster such as filehosting.org and post the URL they give you together with your symptoms in the mailing list. A gzip compression of the report is typically 6 Kbytes so you could also attach it to an e-mail to the list.
If you want your report to include the NUT activity logged by journald, then you should also download the nut-journal script.
You will want the NUT daemon to start automatically every time the box starts. To start the daemon automatically:
pinta:~ # chkconfig upsd on pinta:~ # chkconfig --list | grep upsd Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. upsd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
The same effect may be obtained with the command:
titan:~ # systemctl enable upsd.service upsd.service is not a native service, redirecting to /sbin/chkconfig Executing /sbin/chkconfig upsd on
You should see the confirmation that the daemon will be automatically started in levels 3 and 5.
Check that the permissions and owners of the key configuration files are as shown in Table 1. Do this carefully and thoroughly. Wrong permissions and ownership are a common source of problems with NUT.
For example in 13.2: Check, and correct if needed, the ownership of the binaries:
pinta:~ # ls -alF /usr/sbin/ups* -rwxr-xr-x 1 root root 64984 Oct 15 2014 /usr/sbin/upsd* -rwxr-xr-x 1 root root 48584 Oct 15 2014 /usr/sbin/upsmon* -rwxr-xr-x 1 root root 31536 Oct 15 2014 /usr/sbin/upssched* -rwxr--r-- 1 rpc daemon 2926 Mar 31 2013 /usr/sbin/upssched-cmd* pinta:~ # chown upsd:daemon /usr/sbin/ups* pinta:~ # chmod 744 /usr/sbin/ups* pinta:~ # ls -alF /usr/sbin/ups* -rwxr--r-- 1 upsd daemon 64984 Oct 15 2014 /usr/sbin/upsd* -rwxr--r-- 1 upsd daemon 48584 Oct 15 2014 /usr/sbin/upsmon* -rwxr--r-- 1 upsd daemon 31536 Oct 15 2014 /usr/sbin/upssched* -rwxr--r-- 1 upsd daemon 2926 Mar 31 2013 /usr/sbin/upssched-cmd*
Experience shows that detection of the USB interface to an Eaton/MGE Ellipse UPS is a delicate matter, and best done during the initial power-on sequence. Note: This problem is limited to the Eaton/MGE Ellipse series devices with combined USB/serial ports also known as USBS ports (RJ-45). It is not a problem with other MGE/Eaton devices.
Check with command lsusb that the UPS is detected:
Bus 003 Device 002: ID 0463:ffff MGE UPS Systems UPS
Try starting the daemon with the command rcupsd start . In openSUSE distributions 12.1 and earlier you see the result directly:
sandrane:~ # rcupsd status Checking for service NUT UPS server unused Checking for service NUT UPS monitor unused sandrane:~ # rcupsd start Starting NUT UPS drivers done Starting NUT UPS server done Starting NUT UPS monitor done sandrane:~ # rcupsd status Checking for service NUT UPS server running Checking for service NUT UPS monitor running
and the following entries appear in /var/log/messages
Dec 29 01:05:00 sandrane usbhid-ups[5510]: Startup successful Dec 29 01:05:00 sandrane upsd[5513]: listening on 127.0.0.1 port 3493 Dec 29 01:05:00 sandrane upsd[5513]: listening on ::1 port 3493 Dec 29 01:05:00 sandrane upsd[5513]: Connected to UPS [Eaton]: usbhid-ups-Eaton Dec 29 01:05:00 sandrane upsd[5514]: Startup successful Dec 29 01:05:00 sandrane upsmon[5517]: Startup successful Dec 29 01:05:00 sandrane upsd[5514]: User upsmaster@::1 logged into UPS [Eaton]
with command ps aux | grep ups showing:
upsd ... Ss 13:19 0:00 /usr/lib/ups/driver/usbhid-ups -a Eaton upsd ... Ss 13:19 0:00 /usr/sbin/upsd -u upsd root ... Ss 13:19 0:00 /usr/sbin/upsmon upsd ... S 13:19 0:00 /usr/sbin/upsmon
Try starting the daemon with the command rcupsd start
sandrane:~ # rcupsd start redirecting to systemctl
The phrase redirecting to systemctl
is SuSE-speak for If
you want to see the output, you will have to use command rcupsd
status
sandrane:~ # rcupsd status upsd.service - LSB: UPS monitoring software (remote/local) Loaded: loaded (/etc/init.d/upsd) Active: active (running) since Sun, 23 Sep 2012 10:37:43 +0200; 22s ago Process: 2815 ExecStop=/etc/init.d/upsd stop (code=exited, status=0/SUCCESS) Process: 4900 ExecStart=/etc/init.d/upsd start (code=exited, status=0/SUCCESS) CGroup: name=systemd:/system/upsd.service ├ 4918 /usr/lib/ups/driver/usbhid-ups -a Eaton ├ 4922 /usr/sbin/upsd -u upsd ├ 4925 /usr/sbin/upsmon └ 4926 /usr/sbin/upsmon Sep 23 10:37:43 sandrane usbhid-ups[4918]: Startup successful Sep 23 10:37:43 sandrane upsd[4921]: listening on 127.0.0.1 port 3493 Sep 23 10:37:43 sandrane upsd[4921]: Connected to UPS [Eaton]: usbhid-ups-Eaton Sep 23 10:37:43 sandrane upsd[4922]: Startup successful Sep 23 10:37:43 sandrane upsd[4900]: Starting NUT UPS server ..done Sep 23 10:37:43 sandrane upsmon[4925]: Startup successful Sep 23 10:37:43 sandrane upsd[4922]: User upsmaster@127.0.0.1 logged into UPS [Eaton] Sep 23 10:37:43 sandrane upsd[4900]: Starting NUT UPS monitor ..done
NUT is started automatically by systemd. Check that it is running:
pinta:~ # ps aux | grep ups upsd 1753 ... Ss Oct06 0:15 /usr/lib/ups/driver/usbhid-ups -a Eaton upsd 1755 ... Ss Oct06 0:03 /usr/sbin/upsd root 1757 ... Ss Oct06 0:00 /usr/sbin/upsmon upsd 1758 ... S Oct06 0:03 /usr/sbin/upsmon
Note the two instances of upsmon, one as user root, the other as user upsd. You can also check the status of the systemd service units as shown in chapters nut-server, nut-monitor and nut-delayed-ups-shutdown. The command nut-journal should show the status of the current boot:
Current boot Oct 06 22:52:22 pinta upsdrvctl[1530]: Using subdriver: MGE HID 1.32 Oct 06 22:52:22 pinta upsdrvctl[1530]: Network UPS Tools - Generic HID driver 0.38 (2.7.1) Oct 06 22:52:22 pinta upsdrvctl[1530]: USB communication driver 0.32 Oct 06 22:52:23 pinta upsd[1754]: listening on 127.0.0.1 port 3493 Oct 06 22:52:23 pinta upsd[1754]: Connected to UPS [Eaton]: usbhid-ups-Eaton Oct 06 22:52:23 pinta upsd[1755]: Startup successful Oct 06 22:52:23 pinta upsmon[1757]: Startup successful Oct 06 22:52:23 pinta upsd[1755]: warning: /etc/hosts.allow, line 84: Unable to handle client address: localhost Oct 06 22:52:23 pinta upsd[1755]: User upsmaster@127.0.0.1 logged into UPS [Eaton] Oct 06 22:52:23 pinta hosts.allow[1762]: upsd@127.0.0.1 (host localhost/pinta) accepts access to upsd from upsmaster@localhost Oct 06 22:52:23 pinta upsd[1755]: warning: /etc/hosts.allow, line 84: Unable to handle client address: localhost Oct 06 22:52:23 pinta hosts.allow[1764]: upsd@127.0.0.1 (host localhost/pinta) accepts access to upsd from upsmaster@localhost Oct 06 22:52:23 pinta upsdrvctl[1530]: Network UPS Tools - UPS driver controller 2.7.1 Oct 06 22:52:23 pinta upsd[1754]: fopen /var/lib/ups/upsd.pid: No such file or directory Oct 06 22:52:23 pinta upsd[1754]: listening on 127.0.0.1 port 3493 Oct 06 22:52:23 pinta upsd[1754]: Connected to UPS [Eaton]: usbhid-ups-Eaton Oct 06 22:52:23 pinta upsmon[1756]: fopen /var/run/upsmon.pid: No such file or directory Oct 06 22:52:23 pinta upsmon[1756]: UPS: Eaton@localhost (master) (power value 1) Oct 06 22:52:23 pinta upsmon[1756]: Using power down flag file /etc/killpower
The command upsc -L should show Eaton: Eaton
Ellipse ECO 1600
, and the command upsc Eaton will
give full details of the UPS:
battery.charge: 100 battery.charge.low: 20 battery.runtime: 3000 battery.type: PbAc device.mfr: EATON device.model: Ellipse ECO 1600 device.serial: 000000000 device.type: ups driver.name: usbhid-ups driver.parameter.offdelay: 60 driver.parameter.ondelay: 70 driver.parameter.pollfreq: 30 driver.parameter.pollinterval: 2 driver.parameter.port: auto driver.parameter.vendorid: 0463 ... ups.delay.shutdown: 60 ups.delay.start: 70 ups.firmware: 01 ups.load: 9 ups.mfr: EATON ups.model: Ellipse ECO 1600 ups.power.nominal: 1600 ups.productid: ffff ups.serial: 000000000 ups.status: OL CHRG ups.timer.shutdown: 0 ups.timer.start: 0 ups.vendorid: 0463
If you are using a systemd service unit to shutdown the UPS unit, check that systemd's final target calls for the UPS delayed shutdown:
rprice@maria:~> ls -lF /etc/systemd/system/final.target.wants/ lrwxrwxrwx 1 root root 48 Aug 12 12:31 nut-delayed-ups-shutdown.service -> /etc/systemd/system/nut-delayed-ups-shutdown.service
If you do not see the link, then you have not enabled the unit. See chapter nut-delayed-ups-shutdown.
Pull the power plug from the wall socket for just 30 seconds. Since I use LXDE rather than KDE I get the following messages on an lxterminal. KDE may have a more sophisticated presentation.
Broadcast message from upsd@pinta (somewhere) (Fri Oct 9 10:53:35 2015): UPS Eaton@localhost: On battery +++ Onduleur sur batterie Broadcast message from upsd@pinta (somewhere) (Fri Oct 9 10:53:41 2015): Running on battery, OB DISCHRG 100% - possible shutdown in 2 minutes - save you r work! +++ Sur batterie - arret possible en 2 minutes - sauvez votre travail! Broadcast message from upsd@pinta (somewhere) (Fri Oct 9 10:54:10 2015): UPS Eaton@localhost: On line power +++ Onduleur sur secteur Broadcast message from upsd@pinta (somewhere) (Fri Oct 9 10:54:10 2015): Power back, OL CHRG 99% - shutdown cancelled. +++ Secteur de retour - arret aba ndonne.
Pre-13.2 : To see a trace of the work done by upssched and the script upssched-cmd, you must look at file /var/log/messages.
13.2 : To see a trace of the work done by upssched and the script upssched-cmd, use command nut-journal:
pinta:~ # nut-journal ... Oct 09 10:53:35 pinta upsmon[1758]: UPS Eaton@localhost: On battery +++ Onduleur sur batterie Oct 09 10:53:35 pinta upssched[12058]: Timer daemon started Oct 09 10:53:35 pinta upssched[12058]: New timer: two-minute-warning-timer (5 seconds) Oct 09 10:53:35 pinta upssched[12058]: New timer: one-minute-warning-timer (65 seconds) Oct 09 10:53:35 pinta upssched[12058]: New timer: shutdown-timer (125 seconds) Oct 09 10:53:40 pinta upssched[12058]: Event: two-minute-warning-timer Oct 09 10:53:40 pinta upssched-cmd[12060]: Calling upssched-cmd two-minute-warning-timer Oct 09 10:53:41 pinta upssched-cmd[12063]: Two minute warning timeout reached, OB DISCHRG 100% Oct 09 10:54:10 pinta upsmon[1758]: UPS Eaton@localhost: On line power +++ Onduleur sur secteur Oct 09 10:54:10 pinta upssched[12058]: Cancelling timer: one-minute-warning-timer Oct 09 10:54:10 pinta upssched[12058]: Cancelling timer: shutdown-timer Oct 09 10:54:10 pinta upssched[12069]: Executing command: ups-back-on-line Oct 09 10:54:10 pinta upssched-cmd[12071]: Calling upssched-cmd ups-back-on-line Oct 09 10:54:10 pinta upssched-cmd[12074]: ups_back-on-line: removing timers, OL CHRG 99% Oct 09 10:54:10 pinta upssched-cmd[12078]: UPS back on-line, timers removed, OL CHRG 99% Oct 09 10:54:23 pinta upssched[12058]: Timer queue empty, exiting
For a full test, pull the power plug from the wall socket. You should see
Push the power plug back into the wall socket, and you should see a complete system restart. See nut-journal for a trace of NUT activity during the shutdown.
NUT as packaged in openSUSE 11.3 and since is sensitive to the operation of IPv4 and IPv6. These are both turned on by default in the openSUSE distribution. What happens if I turn IPv6 off? First some background from Arjen de Korte:
A couple of releases ago we decided to no longer listen on all interfaces, but instead only on the loopback interface. This in order to not automatically expose the upsd service on systems that are connected to the internet (which is a security risk if you don't protect the communication through SSL). In order to allow the least amount of surprises for people that are upgrading their systems, we decided to listen to both the IPv4 and IPv6 loopback addresses if IPv6 support is detected at compilation time. In most of the cases, there is really no benefit to switch off IPv6 and in the rare cases there is, there is an option that can be passed to the upsd server to override this default.
This means that if you turn off IPv6, you need to adjust your NUT
configuration to take this into account. See upsd.conf and man 5
upsd.conf
.
Notes:
You may wish to change the battery low value on your UPS. To see the current value use the command
pinta:~ # upsc <myups> battery.charge.low 20
To change the value to say 36 use the command
pinta:~ # upsrw -s battery.charge.low=36 -u <userid> -p <pass> <myups>
where
and if all goes well you will see the acknowledgement at the bottom of the output of nut-journal, or in /var/log/messages on a pre-13.2 system.
Oct 29 22:02:34 pinta upsd[1739]: Set variable: upsmaster@127.0.0.1 set battery.charge.low on Eaton to 36
The new value can also be checked using
pinta:~ # upsc <myups> battery.charge.low 36
This chapter proposes a heartbeat technique for regular verification of the operational integrity of a NUT installation.
A NUT configuration may run for months with little or no output to a system administrator to assure that the combined processes are running correctly. The technique described here verifies that the ups driver, upsd, upsmon, upssched and upssched-cmd components are operational and that the flow of data between them is effective. The system administrator is warned if the overall combined process breaks.
An 11 minute upssched timer runs permanently, and when it completes,
upssched-cmd sends a warning message to the sysadmin. During normal
operation the timer is prevented from completing by a timed process with a
shorter 10 minute period running in a dummy UPS known as heartbeat
. The
dummy UPS heartbeat
cycles through an OL and an OB every 10 minutes,
and the status changes are communicated to upsd and then to upsmon
and upssched. Thus every 10 minutes upssched stops and restarts
the 11 minute timer. During normal operation the 11 minute timer will never
complete, but if the driver → upsd → upsmon →
upssched chain is broken, it will complete and the sysadmin advised.
The technique requires a working NUT installation and an understanding of upssched timers and the upssched-cmd script.
[heartbeat] driver = dummy-ups port = heartbeat.dev desc = "Heart beat verification of NUT"
See man dummy-ups
for more detail on the operation of the dummy UPS.
ups.status: OL TIMER 300 ups.status: OB TIMER 300
The dummy UPS will cycle continuously through this script. Remember that the are no comments in NUT .dev files.
MONITOR heartbeat@localhost 1 upsmaster s3cr3t master
Your password may be better than mine. Make sure that you have specified
NOTIFYCMD /usr/sbin/upssched NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
You may want to remove the WALL after testing the heartbeat setup.
# Heart beat verification that NUT is operational. # Restart timer which completes only if the dummy-ups heart beat has stopped. # See timer values in heartbeat.dev AT ONBATT heartbeat@localhost CANCEL-TIMER heartbeat-failure-timer AT ONBATT heartbeat@localhost START-TIMER heartbeat-failure-timer 660
and make sure that there are no entries such as
AT ONLINE * ... AT ONBATT * ...
Replace the "*" with the full address of the ups unit, e.g. Eaton@localhost
Make sure that you have specified
CMDSCRIPT /usr/sbin/upssched-cmd
upssched-cmd heartbeat-failure-timer
heartbeatis running. Command ps aux | grep ups should show something like
upsd 14785 0.0 0.0 13228 652 ? Ss 22:48 0:00 /usr/lib/ups/driver/usbhid-ups -a Eaton upsd 14787 0.0 0.0 19624 704 ? Ss 22:48 0:00 /usr/lib/ups/driver/dummy-ups -a heartbeat upsd 14791 0.0 0.0 17560 744 ? Ss 22:48 0:00 /usr/sbin/upsd -u upsd root 14794 0.0 0.0 19432 664 ? Ss 22:48 0:00 /usr/sbin/upsmon upsd 14795 0.0 0.0 19856 1616 ? S 22:48 0:00 /usr/sbin/upsmon upsd 14845 0.0 0.0 6408 448 ? S 22:53 0:00 /usr/sbin/upssched UPS heartbeat@localhost: On battery
Note the presence of the dummy UPS heartbeat
, and the permanent
activity of upssched processing the timer heartbeat-failure-timer.
heartbeatrestarting the 11 minute timer every 10 minutes.
avril 03 10:06:30 maria upsmon[14795]: UPS heartbeat@localhost: On battery +++ Onduleur sur batterie avril 03 10:06:30 maria upssched[14845]: Cancelling timer: heartbeat-failure-timer avril 03 10:06:30 maria upssched[14845]: New timer: heartbeat-failure-timer (660 seconds)
A few notes on personal experiences.
Jan 5 03:40:59 cyan upsmon [9847]: Login on UPS [Eaton@localhost] failed - got [ERR ACCESS-DENIED]
then maybe your file /etc/hosts.allow does not allow
protocol upsd from 127.0.0.1 or [::1]. See
hosts.allow, and
man tcpd
, man -S5 hosts_access
and man -S5
hosts_options
for a detailed description of hosts.allow and
hosts.deny.
Broadcast Message from upsd@glacon2 (somewhere) at 22:55 ... UPS Eaton@localhost is unavailable
Note: This is typical for usbhid-ups driver and the MGE/Eaton Ellipse series with NUT versions before 2.4.2. It has to do with a reply from the UPS that was misunderstood by the driver, occasionally resulting in a storm of reconnects. This effect is limited to the MGE/Eaton Ellipse series, other MGE/Eaton devices are not affected by this problem.
Broadcast Message from upsd@glacon2 (somewhere) at 19:10 ... UPS Eaton@localhost: Not available +++ Onduleur indisponible
I suspect that this is also a peculiarity of the MGE/Eaton Ellipse series with the usbhid-ups driver. Somehow they become synchronised in their inability to connect. The fix is to restart the UPS daemon with the command rcupsd restart. This de-synchronises the driver and the UPS.
Starting NUT UPS drivers ....done Starting NUT UPS server startproc: exit status of parent of /usr/sbin/upsd: 1 ....failed
File /var/log/messages tails with
Nov 7 09:53:57 glacon usbhid-ups[4974]: Startup successful Nov 7 09:53:57 glacon upsd[4977]: listening on 127.0.0.1 port 3493 Nov 7 09:53:57 glacon upsd[4977]: not listening on ::1 port 3493 Nov 7 09:53:59 glacon usbhid-ups[4974]: Signal 15: exiting
This can happen if you turn IPv6 off, but forget to change upsd.conf. See configuration file upsd.conf for the required modification, then run the command rcupsd restart.
Alternatively, you can turn IPv6 on again: YaST =>
Network Devices => Network Settings => Global options => IPv6 Protocol
Settings and select Enable IPv6
and then re-boot.
Broadcast Message from upsd@glacon2 (somewhere) at 16:34 ... UPS Eaton@localhost: On battery +++ Onduleur sur batterie
but no further messages. Neither nut-journal nor the file /var/log/messages shows any trace of activity by upssched-cmd. The problem is with the permissions of script upssched-cmd:
glacon2:~ # ls -alF /usr/sbin/upssched-cmd -rw-r--r-- 1 upsd daemon 1936 2010-02-28 16:17 /usr/sbin/upssched-cmd
Once the permissions were changed to conform to table 1
glacon2:~ # chmod 744 /usr/sbin/upssched-cmd glacon2:~ # ls -alF /usr/sbin/upssched-cmd -rwxr--r-- 1 upsd daemon 1936 2010-02-28 16:17 /usr/sbin/upssched-cmd*
the script executes correctly.
Broadcast Message from upsd@glacon2 (somewhere) at 16:34 ... UPS Eaton@localhost: On battery +++ Onduleur sur batterie
but no further messages. Neither nut-journal nor the file /var/log/messages shows any trace of activity by upssched-cmd. The problem is with NOTIFYFLAG entries in upsmon.conf. You need to add the +EXEC option to the cases for which you want action. I have +EXEC set on all the NOTIFYFLAG's.
Broadcast Message from upsd@glacon2 (somewhere) at 16:34 ... UPS Eaton@localhost: On battery +++ Onduleur sur batterie
but there was no further activity and no shutdown. The file /var/log/messages shows
Feb 19 11:15:26 sandrane upsmon[3435]: UPS Eaton@localhost: On battery +++ Onduleur sur batterie Feb 19 11:15:33 sandrane upssched[4720]: Failed to connect to parent and failed to create parent: No such file or directory
The problem may be that in file upssched.conf you specified
PIPEFN /var/lib/ups/upssched/upssched.pipe LOCKFN /var/lib/ups/upssched/upssched.lock
but there is no directory /var/lib/ups/upssched. PIPEFN and LOCKFN are now in directory /var/lib/ups/. You should have specified
PIPEFN /var/lib/ups/upssched.pipe LOCKFN /var/lib/ups/upssched.lock
If you examine directory /var/lib/ups/ you should see:
sandrane:~ # ls -alF /var/lib/ups total 20 drwx------ 3 upsd daemon 4096 19 févr. 11:53 ./ drwxr-xr-x 44 root root 4096 19 févr. 10:47 ../ -rw-r--r-- 1 upsd daemon 5 19 févr. 11:10 upsd.pid srw-rw---- 1 upsd daemon 0 19 févr. 11:10 usbhid-ups-Eaton= -rw-r--r-- 1 upsd daemon 5 19 févr. 11:10 usbhid-ups-Eaton.pid
cyan upsmon[4340]: UPS [Eaton@localhost]: connect failed: Connection failure: Connection refused
every 5 seconds. Has the UPS been stolen? No, it's still there. The command lsusb shows
Bus 002 Device 002: ID 0463:ffff MGE UPS Systems UPS
Is the upsd daemon which sits between the UPS drivers and the monitoring programs still operational? The command ps aux | grep upsd shows no activity. upsd is dead. I tried restarting the daemon with the command rcupsd restart:
cyan:~ # rcupsd restart Shutting down NUT UPS monitor done Shutting down NUT UPS server done Shutting down NUT UPS drivers done Starting NUT UPS drivers done Starting NUT UPS server startproc: exit status of parent of /usr/sbin/upsd: 1
This error appeared when the server executing the NUT daemon was repositioned in the local network. It was taken from it's place as a router receiving traffic directly from the Internet to a subsidiary position below another router. The IP number changed as did the FQDN (fully qualified domain name), however no changes were made to the server configuration. The problem was solved by returning the server to it's previous rôle as a router, and the problem was not investigated any further.
This is a problem since openSUSE 12.2: see the chapter Setup and the Race for a fix.
If you wish to know which UPS values are variables which can be
changed, use command upsrw ups-name where ups-name
must match the name of the UPS defined in ups.conf. Our example has
ups-name Eaton
.
cyan:~ # upsrw Eaton ... [ups.delay.shutdown] Interval to wait after shutdown with delay command (seconds) Type: STRING Value: 30 [ups.delay.start] Interval to wait before (re)starting the load (seconds) Type: STRING Value: 40
You can also check the values of the variables using the commands
cyan:~ # upsc Eaton ups.delay.shutdown 30 cyan:~ # upsc Eaton ups.delay.start 40
To change the values of the variables, see options offdelay and ondelay in chapter ups.conf.
In general, if you want to know which commands the UPS unit will accept, use command upscmd -l ups-name.
These commands assume that you have a running NUT installation.
To remedy the situation, I added a "low battery" shutdown procedure to my setup. This involved making changes to upssched.conf where I added the new timer definition
# Defective UPS runs down on its own for no reason! # Give warning and turn off box in 30 seconds AT LOWBATT * START-TIMER low-battery-timer 5 AT LOWBATT * START-TIMER shutdown-timer 65
I also updated upssched-cmd to include the additional timer handling
# Defective UPS runs down on its own for no reason. # On low battery, warn about quick system shutdown. low-battery-timer) logger -i -t upssched-cmd "Low battery warning, $CHMSG" echo $MSG4 | wall ;;
Note that when timer shutdown-timer runs out, the existing upssched-cmd configuration will shut down the server.
On batterywarning, but no shutdown : The command rcupsd status reports
Checking for service NUT UPS server ..running Checking for service NUT UPS monitor ..running upsd.service - LSB: UPS monitoring software (remote/local) Loaded: loaded (/etc/init.d/upsd) Active: active (running) since Mon 2013-12-02 21:45:17 CET; 6min ago Process: 11265 ExecStop=/etc/init.d/upsd stop (code=exited, status=0/SUCCESS) Process: 11311 ExecStart=/etc/init.d/upsd start (code=exited, status=0/SUCCESS) CGroup: /system.slice/upsd.service ├─11329 /usr/lib/ups/driver/usbhid-ups -a Eaton ├─11333 /usr/sbin/upsd -u upsd ├─11336 /usr/sbin/upsmon └─11337 /usr/sbin/upsmon Dec 02 21:45:17 pinta upsd[11332]: listening on 127.0.0.1 port 3493 Dec 02 21:45:17 pinta upsd[11332]: Connected to UPS [Eaton]: usbhid-ups-Eaton Dec 02 21:45:17 pinta upsd[11333]: Startup successful Dec 02 21:45:17 pinta upsd[11311]: Starting NUT UPS server ..done Dec 02 21:45:17 pinta upsmon[11336]: Startup successful Dec 02 21:45:17 pinta upsd[11333]: User upsmaster@127.0.0.1 logged into UPS [Eaton] Dec 02 21:45:17 pinta upsd[11311]: Starting NUT UPS monitor ..done Dec 02 21:45:17 pinta systemd[1]: Started LSB: UPS monitoring software (remote/local).
in which one sees clearly the two upsmon processes 11336 and 11337. Command ps aux | grep ups reports
upsd 11329 0.0 0.0 13232 644 ? Ss 21:45 0:00 /usr/lib/ups/driver/usbhid-ups -a Eaton upsd 11333 0.0 0.0 19848 1080 ? Ss 21:45 0:00 /usr/sbin/upsd -u upsd root 11336 0.0 0.0 19388 656 ? Ss 21:45 0:00 /usr/sbin/upsmon upsd 11337 0.0 0.0 19812 816 ? S 21:45 0:00 /usr/sbin/upsmon
All this looks perfect, so what's gone wrong?
Yet again there are file permission and ownership problems with this new installation. The ownerships and permissions are currently
pinta:~ # ls -alF /usr/sbin/ups* -rwxr-xr-- 1 root root 64904 Sep 28 11:05 /usr/sbin/upsd* -rwxr-xr-- 1 root root 44416 Sep 28 11:05 /usr/sbin/upsmon* -rwxr-xr-- 1 root root 31464 Sep 28 11:05 /usr/sbin/upssched* -rwxr--r-- 1 upsd daemon 2926 Mar 31 2013 /usr/sbin/upssched-cmd*
This does not correspond to those given in Table 1. Correct the error:
pinta:~ # chmod 744 /usr/sbin/ups* pinta:~ # chown upsd:daemon /usr/sbin/ups* pinta:~ # ls -alF /usr/sbin/ups* -rwxr--r-- 1 upsd daemon 64904 Sep 28 11:05 /usr/sbin/upsd* -rwxr--r-- 1 upsd daemon 44416 Sep 28 11:05 /usr/sbin/upsmon* -rwxr--r-- 1 upsd daemon 31464 Sep 28 11:05 /usr/sbin/upssched* -rwxr--r-- 1 upsd daemon 2926 Mar 31 2013 /usr/sbin/upssched-cmd*
Restart upsd with command systemctl restart upsd.service and the problem is solved.
As one of the many who have used the work of the NUT project as part of their system setup, I would like to express my gratitude and my appreciation for the software that the NUT project has made available to system administrators.
Much of the code and text in this page is derived from work by the NUT project, MGE/Eaton and contributions by Charles Lepple, Arjen de Korte, Arnaud Quette and others in the Nut-upsuser mailing list.
The <HTML> element of this page with its content is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The <HTML> element is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this page. If not, see <http://www.gnu.org/licenses/>.
To republish this page, you will need to place a valid DOCTYPE declaration before the <HTML> element.
© Copyright 2005-2022 Roger Price < webmaster at rogerprice dot org >
In order to facilitate access from all browsers, now and in the future,
these pages conform to the International Standard ISO/IEC 15445 and the
corresponding W3C Recommendations.
Last change:
2022-11-10 17:41:26 CET
https://rogerprice.org