Home > DIY, Software, ubuntu > Network UPS Tools (NUT) on Ubuntu

Network UPS Tools (NUT) on Ubuntu

NUT is a handy system for monitoring almost any UPS. Unfortunately the configuration process is tweaky and the included documentation is minimal and cryptic.

Here is a process that worked for me:

(Adapted from Engadget)

Open the Synaptic Package Manager (under the System->Administration menu) and search for ‘nut’. Select the package for installation and click on Apply.
Now log in as the superuser, then create and edit five configuration files:

sudo su

1: /etc/default/nut

nano /etc/default/nut

Change this:

# start upsd
START_UPSD=no

# start upsmon
START_UPSMON=no
to this:

# start upsd
START_UPSD=yes

# start upsmon
START_UPSMON=yes
(Ctrl-x, then y to exit and save)

2: /etc/nut/ups.conf

nano /etc/nut/ups.conf

The configuration is pretty simple. Check the compatibility list to find out what driver/upstype to specify. For my APC SmartUPS, I used the apcsmart driver, and serial port ttyS0:

[ups1]
driver=apcsmart
port=/dev/ttyS0

(Ctrl-x, then y to exit and save)
to test:

upsdrvctl start

I got this message:

Unable to open /dev/ttyS0: Permission denied

Current user id: nut (120)
Serial port owner: root (0)
Serial port group: dialout (20)
Mode of port: 0660

To resolve it permanently, a quick workaround is to add nut to the dialout group in Users and Groups (under the System->Administration menu).

Now test again:

upsdrvctl start

and I got:

Detected SMART-UPS 1000 [WS9730021313] on /dev/ttyS0

now stop upsdrvctl:

upsdrvctl stop

Done with that!

3: /etc/nut/upsd.conf

nano /etc/nut/upsd.conf

If you want to allow your local network, put in the network address (i.e. 10.0.1.0/24)

ACL all 0.0.0.0/0ACL remote 10.0.1.0/24

ACL localhost 127.0.0.1/32ACCEPT localhost

ACCEPT remote

REJECT all

(Ctrl-x, then y to exit and save)

4: /etc/nut/upsd.users

nano /etc/nut/upsd.users

Add the following:

[monuser]

password = changeme

allowfrom = local

upsmon master

(replace changeme with a good password)

5: /etc/nut/upsmon.conf

nano /etc/nut/upsmon.conf

Add the following:

MONITOR ups1@localhost 1 monuser changeme master
SHUTDOWNCMD "/sbin/shutdown -h +0"

(replace changeme with the good password you used in step 4)

Now start the service:

 /etc/init.d/nut start

and test the settings:

upsc ups1@localhost

You should get a slew of readings and settings from the ups:

battery.alarm.threshold: 0
battery.charge: 100.0
battery.charge.restart: 00
battery.date: 07/24/97
battery.packs: 000
battery.runtime: 2640
battery.runtime.low: 120
battery.voltage: 27.74
battery.voltage.nominal: 024
driver.name: apcsmart
driver.parameter.port: /dev/ttyS0
driver.version: 2.0.3
driver.version.internal: 1.99.7
input.frequency: 60.00
input.quality: FF
input.sensitivity: H
input.transfer.high: 132
input.transfer.low: 103
input.transfer.reason: S
input.voltage: 119.6
input.voltage.maximum: 120.2
input.voltage.minimum: 119.6
output.voltage: 119.6
output.voltage.target.battery: 115
ups.delay.shutdown: 020
ups.delay.start: 000
ups.firmware: 60.9.D
ups.id: UPS_IDEN
ups.load: 033.2
ups.mfr: APC
ups.mfr.date: 07/24/97
ups.model: SMART-UPS 1000
ups.serial: WS9730021313
ups.status: OL
ups.temperature: 029.7
ups.test.interval: 0
ups.test.result: NO
root@ubuntusrv:/etc# upsc ups1@localhost
battery.alarm.threshold: 0
battery.charge: 100.0
battery.charge.restart: 00
battery.date: 07/24/97
battery.packs: 000
battery.runtime: 2700
battery.runtime.low: 120
battery.voltage: 27.74
battery.voltage.nominal: 024
driver.name: apcsmart
driver.parameter.port: /dev/ttyS0
driver.version: 2.0.3
driver.version.internal: 1.99.7
input.frequency: 60.00
input.quality: FF
input.sensitivity: H
input.transfer.high: 132
input.transfer.low: 103
input.transfer.reason: S
input.voltage: 120.2
input.voltage.maximum: 120.2
input.voltage.minimum: 119.6
output.voltage: 120.2
output.voltage.target.battery: 115
ups.delay.shutdown: 020
ups.delay.start: 000
ups.firmware: 60.9.D
ups.id: UPS_IDEN
ups.load: 033.2
ups.mfr: APC
ups.mfr.date: 07/24/97
ups.model: SMART-UPS 1000
ups.serial: WS9730021313
ups.status: OL
ups.temperature: 029.7
ups.test.interval: 0
ups.test.result: NO

Another test: Push and hold the test button on the smartups, or briefly unplug the ups from the wall. You should see messages pop up in the terminal window:

Broadcast Message from nut@ubuntusrv
(somewhere) at 13:58 …

UPS ups1@localhost on battery

Broadcast Message from nut@ubuntusrv
(somewhere) at 13:58 …

UPS ups1@localhost on line power

It is working!

To add a windows client, download and install WinNUT.

At the configuration tool,you can leave everything at the defaults. All you need to do is edit the configuration file. (Click the Edit button to the right of the Configuration File Path).

Enter the same line as in upsmon.conf, changing localhost to the actual IP address of the ubuntu machine, and use ‘slave’ instead of ‘master’:

MONITOR ups1@10.0.1.105 1 monuser changeme slave

(replace changeme with the good password you used in step 4)

You should be good to go.

Categories: DIY, Software, ubuntu
  1. skipperthemadpenguin
    July 12, 2007 at 3:48 pm

    hi, very useful tnx you!!!

    may ask something?
    i have only 1 pc running ubuntu with nut properly configured. if ups switch to battery when my pc is shutdown ? when battery is low? or immediately ?
    it’s possible to configure the monitor like that: “after 15 min of battery mode shutdown immediately”

    TNX

  2. rescdsk
    October 31, 2007 at 12:46 pm

    Thanks for posting this!

    I got stalled at the “upsdrvctl start” step: it would not detect my UPS’s existence. My UPS is connected over USB, with the parameters:
    (ups.conf)
    [belkin]
    driver=newhidups
    port=auto

    The problem turned out to be that the newhidups driver did not have sufficient permissions to read and write the device node that corresponded to the UPS. I have a 2.6 kernel, so this just means I needed to write a udev rule. The Ubuntu nut package automatically adds a file to /etc/udev/rules.d/, but my UPS was not detected by the rules in that file. So I added the following line to it:

    SYSFS{product}==”Belkin UPS”, SYSFS{idProduct}==”0751″, SYSFS{version}==” 1.10″,
    RUN+=”/etc/hotplug/usb/libhidups”

    That hotplug script simply changes the ownership of the device node. Then everything worked, after I unplugged and plugged in the USB cable.

    I figured out the SYSFS{..} rules using the lsusb program and the udevinfo program. The former is pretty self-explanatory, the latter is described in the “writing udev rules” link above.

    By the way, another hard to figure out piece of excitement is that the “usbhid-ups” and “newhidups” drivers are really the same thing, and if someone tells you to use one but you only have the other, try the other.

    Hope this helps someone!
    tgs at dont resc spamme dot net

  3. bahadirtonguc
    November 29, 2008 at 5:06 am

    I tried everything but it wont work. is that because of using a regular serial cable with 9 pins both ends?

    ttyS0 is showing locked. ttyS1 received data -1 instead of 11 which driving me crazy!

    UPS is powercom, OS ubuntu, Server IBM Netfinity 5600

    Pleased to hear

  4. ericcoe
    August 4, 2009 at 6:44 pm

    the key to nut and BNT-1500AP is this as your ups.conf file.
    [mine]
    driver = powercom
    port = /dev/ttyS0
    type = “BNT-other”

    If your read the help page for the driver:
    /lib/nut/powercom -h

    You will find that:
    You must specify type in ups.conf
    Type of UPS like ‘Trust’, ‘Egys’, ‘KP625AP’, ‘IMP’, ‘KIN’ or ‘BNT’ or ‘BNT-other’ (default: ‘Trust’)
    BNT-other – it’s a special type for BNT 100-120V models

  1. July 1, 2007 at 5:39 pm
  2. September 27, 2007 at 11:20 pm
  3. April 6, 2008 at 1:51 pm
  4. January 14, 2011 at 4:31 pm
  5. July 23, 2012 at 9:50 am

Leave a comment