wiki.ipfire.org

The community-maintained documentation platform of IPFire

User Tools

Site Tools


addons:nut:start

Network UPS Tools (NUT)

NUT is an uninterruptible power supply (UPS) monitoring system that allows the sharing of one (or more) UPS systems between several computers. It has a 'server' component, which monitors the UPS status and notifies a 'client' component when the UPS has a low battery. There can be multiple computers running the client component and each can be configured to shut down cleanly in a power failure (before the UPS batteries run out of charge).

  • The IPFire NUT package contains the core system as well as the serial and USB UPS drivers. It allows a complete UPS monitoring system.
  • NUT supports a large number of UPS devices. These are listed in the NUT Hardware compatibility list.
  • NUT itself is split in to multiple modules. These make it appear complicated but allow it to be highly customizable.

There are two ways to monitor a UPS with NUT:

  1. A direct, local connection (USB or Serial)
  2. Using another network device (computer or NAS) which itself is direct connected and is running NUT in Network-Server configuration.

NOTE: There are multiple ways to configure NUT. These instructions are the simplest for a UPS connected directly to IPFire only.

There are also detailed instructions here which cover additional options, such as notifying other servers when a UPS is about to run out of power, email status notifications and more detail about the whole process.

Simple NUT configuration using official documentation

This procedure is based on the official NUT user manual for an IPFire system connected to a single UPS with no other network-based clients.

Although you can configure a UPS without testing, it is best that you prepare for a controlled outage of IPFire at the end of this procedure to test that your configuration works.

Configure a nutmon user and group

While nut can run entirely as root, it is best to run the “upsmon” monitoring process without root privileges. To do this we must create a new user and group.

  1. Connect to your IPFire system as root through SSH.
  2. Create a “nut” group
    • groupadd nut
  3. Create a “nutmon” user, who should not have a login shell
    • useradd nutmon -g nut -s /sbin/nologin

Monitor a locally connected UPS

  1. Identify your UPS in the NUT Hardware Compatibility List and take a note of the Driver listed
  2. Connect to IPFire using ssh (or log in to the console) as “root”
  3. Make a copy of the ups.conf sample file:
    • cp /etc/nut/ups.conf.sample /etc/nut/ups.conf
  4. Modify ups.conf to add an entry for your UPS:
  5. Make a copy of the upsd.conf sample file:
    • cp /etc/nut/upsd.conf.sample /etc/nut/upsd.conf
  6. Edit the file and uncomment the localhost entry, so that NUT will listen only on the local interface. The file should only have one line uncommented (one line which does not begin with “#”)
    • LISTEN 127.0.0.1 3493
  7. Make a copy of the users.conf sample file (you do not need to configure this file yet):
    • cp /etc/nut/upsd.users.sample /etc/nut/upsd.users
  8. Change permissions on these two configuration files so only root can read them:
    • chown root:root upsd.conf upsd.users
    • chmod 0640 upsd.conf upsd.users
  9. Start the driver(s) for your UPS
    • /usr/sbin/upsdrvctl start
    • Which should produce output similar to this:
    • Network UPS Tools - UPS driver controller 2.7.2
          Network UPS Tools - Generic HID driver 0.38 (2.7.2)
          USB communication driver 0.32
          Using subdriver: MGE HID 1.33
    • If the previous command returns an error, saying that it cannot connect to a UPS or it reports that the data is stale you must resolve the problem before continuing. Either your ups.conf file is incorrect or you may have not chosen the correct driver for your UPS.

  10. Before starting the 'upsd' UPS server, tighten security by removing world read access from a special state directory
    • chmod 0750 /var/state/ups
  11. Start the 'upsd' daemon
    • /usr/sbin/upsd
    • Ensure that it connects to the driver on your IPFire system (ignore any warnings about a .pid file):
    • Network UPS Tools upsd 2.7.2
      fopen /var/state/ups/upsd.pid: No such file or directory
      listening on 127.0.0.1 port 3493
      Connected to UPS [eaton3s]: usbhid-ups-eaton3s
    • If there are any errors (except for the warning about the .pid file) they must be resolved before the rest of these instructions can be followed

  12. Check that the configuration is working and your UPS is providing good status data:
    • upsc <myupsname>@localhost ups.status
    • OR:
      upsc <myupsname>@localhost
    • For example:
      upsc eaton3s@localhost ups.status
    • produces: OL (Online) or OL CHRG (Online Charging)

Configure automatic shutdown at low battery

  1. Edit /etc/nut/upsd.user and create a upsd user with a strong password of your own:
    • [admin]
                      password = "PLZset@strongpassw0rdh3r3!"
                      actions = SET
                      instcmds = ALL
  2. Reload upsd:
    /usr/sbin/upsd -c reload
  3. Configure a “flag” file which is created to indicate that UPS needs to be powered off during a power failure, when low battery is reached
    • Edit /etc/nut/upsmon.conf
    • Check that that an entry for POWERDOWNFLAG /etc/killpower exists and is not commented out with a '#'
  4. Create MONITOR directive in upsmon
    • Edit /etc/nut/upsmon.conf again
    • Uncomment one of the examples and change it to match your use, just update the username and password to match the one which you set in step 1.
    • MONITOR eaton3s@localhost 1 admin "PLZset@strongpassw0rdh3r3!" master
  5. Un-comment the SHUTDOWNCMD directive
    • While still editing /etc/nut/upsmon.conf, remove the “#” before SHUTDOWNCMD. It should look like this:
    • SHUTDOWNCMD "/sbin/shutdown -h +0"
  6. Secure all the /etc/nut configuration files
    • chown root:nut /etc/nut/*
      chmod 640 /etc/nut/*
  7. Secure the special “state path” directory
    • chown root:nut /var/state/ups
      chmod 0770 /var/state/ups
    • chown root:nut /etc/nut/upsmon.conf
    • chmod 640 /etc/nut/upsmon.conf
  8. Start upsmon
    • /usr/sbin/upsmon
  9. Check the 'messages' log for errors
    • grep upsmon /var/log/messages
    • 'upsmon' may display a confusing error “[ERR ACCESS-DENIED]” in the messages log. This may not indicate an actual failure. If this occurs, follow the instructions below.

      • If you see the error message Login on UPS [your_ups@localhost] failed - got [ERR ACCESS-DENIED] stop upsmon and start it again with debug output enabled:
        • kill `ps aux | grep [u]psmon | awk '{print $2}'`
        • /usr/sbin/upsmon -DD
        • The error will still be displayed, but after a few seconds you should see the upsmon process connect anyway. The evidence is that the UPS status will be shown correctly, for example OL CHRG
  10. Configure which mode NUT will use, in this case “standalone”.
    • edit /etc/nut.nut.conf
    • Add the following text after the last line. All other lines should be commented out with a “#”
    • MODE=standalone
  11. Start NUT
    • /etc/init.d/nut start
    • There should be no errors on the command line.
    • Check the messages log to ensure the three NUT components start (usbhid-ups, upsd and upsmon)
    • grep ups /var/log/messages
  12. Check the Web User Interface
    • Log in to the IPFire WUI using a browser
    • In the Status > Services screen you should see the nut service RUNNING. It will be visible in the “Addon -Services” section.
    • 'nut' will automatically start when IPFire starts up. You can now also start and stop the service from the “Services” screen in the WUI.
    • You should now arrange a Change so that you can to test your configuration by shutting down IPFire on low battery.

    • For detail on how NUT works at a low-power event, see this section of the detailed instructions.

Quick test

Before doing a test with low battery, you can verify that the NUT components are working by switching off the power to your UPS.

  1. Turn off the power to the UPS
    • If you are logged in to IPFire using SSH you should see a broadcast message from nutmon@your_ipfire_server:
    • Broadcast message from nutmon@ipfire (Sat Aug 22 15:43:55 2015): UPS eaton3s@localhost on battery
    • If you missed the broadcast message, check the “messages” log:
    • grep upsmon /var/log/messages
    • For example: Aug 22 15:43:55 ipfire upsmon[7532]: UPS eaton3s@localhost on battery
  2. Turn power back on to the UPS
    • You should see another broadcast message from nutmon@your_ipfire_server:
    • Broadcast message from nutmon@ipfire (Sat Aug 22 15:45:31 2015): UPS eaton3s@localhost on line power
    • If you missed the broadcast message, check the “messages” log:
    • grep upsmon /var/log/messages
    • For example: Aug 22 15:45:45 ipfire upsmon[7532]: UPS eaton3s@localhost on line power
addons/nut/start.txt · Last modified: 2018/09/21 03:10 by Jon