Tag Archives: nut

Manage UPS on FreeBSD

When I wrote about Tiny UPS for Tiny NAS Reloaded or about Perfect NAS Solution topics – I really thought that this tiny battery would be best for this setup – but it was good only for very short periods of lack of electricity.

I wanted something what would allow my NAS last for at least for couple of hours. After some usual research and considering local market for used things in Poland – as I am a big fan of price/performance ratio – I settled for slightly used Eaton 3S 550F 330W UPS solution … and I paid about $25 for it.

After some simple research I found the NUT tools … and I was wondering if they are ported to FreeBSD … seems they are πŸ™‚

There was only one thing that is the reason for this article – beep.

When the power is gone – NAS runs on the UPS battery – and every several seconds the Eaton 3S 550F 330W UPS makes a beep … and I really did not liked that – so I decided to do something about it.

I even first tried to use some ‘dedicated’ Windows software – but it was such a bullshit that I deleted it minutes later.

UPS on FreeBSD

The Eaton 3S 550F 330W UPS has a USB-B port – so I attached a USB-B <=> USB-A cable between the UPS and my laptop.

It was nothing fancy on the dmesg(8) side.

# dmesg | grep -i eaton
ugen0.2: <EATON Eaton 3S> at usbus0

# usbconfig | grep -i ugen0.2
ugen0.2: <UPS MGE UPS Systems> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (20mA)

The NUT packages installation is very standard.

# pkg install -y nut

NUT

First – lets scan the USB bus for possible devices.

# /usr/local/bin/nutconf --scan-usb
NONE usbhid-ups auto

# /usr/local/bin/nut-scanner
Scanning USB bus.
No start IP, skipping SNMP
Scanning XML/HTTP bus.
No start IP, skipping NUT bus (old connect method)
Scanning NUT simulation devices.
Scanning NUT bus (avahi method).
Failed to create Avahi client: Daemon not running
[nutdev-usb1]
        driver = "usbhid-ups"
        port = "auto"
        vendorid = "0463"
        productid = "FFFF"
        product = "Eaton 3S"
        serial = "Blank"
        vendor = "EATON"
        # bus = "000"
        # device = "002"
        # busport = "001"

So there is a supported UPS.

Lets find out which driver is used for it.

# grep -i -r eaton /usr/local/etc/nut/driver.list
"Eaton"  "ups"   "5"     "3S"    "USB"   "usbhid-ups"

So we will need usbhid-ups driver for it.

We now need to configure NUT framework.

# cat /usr/local/etc/nut/ups.conf
[eaton3s]
driver = usbhid-ups
port = auto

# cat /usr/local/etc/nut/nut.conf
MODE=standalone

# cat /usr/local/etc/nut/upsd.users
[root]
  password = asd
  actions = SET
  instcmds = ALL

Now – we will enable the NUT service and start it.

# service nut enable
nut enabled in /etc/rc.conf

# /usr/local/etc/rc.d/nut start
Network UPS Tools - UPS driver controller 2.8.2
Network UPS Tools - Generic HID driver 0.53 (2.8.2)
USB communication driver (libusb 1.0) 0.47
Using subdriver: MGE HID 1.46
Starting nut.
Network UPS Tools upsd 2.8.2
kill: No such process
listening on ::1 port 3493
listening on 127.0.0.1 port 3493
Connected to UPS [eaton3s]: usbhid-ups-eaton3s
Found 1 UPS defined in ups.conf

Now … the above is output of a successful connection … but there is also a chance that you will se failure like that one below.

# service nut start
Network UPS Tools - UPS driver controller 2.8.2
Network UPS Tools - Generic HID driver 0.53 (2.8.2)
USB communication driver (libusb 1.0) 0.47
libusb1: Could not open any HID devices: no USB buses found
No matching HID UPS found
upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it
Driver failed to start (exit status=1)
/usr/local/etc/rc.d/nut: WARNING: failed precmd routine for nut

If you encounter this problem – first create /etc/devfs.rules file with following content and restart devfs service.

# cat /etc/devfs.rules
[system=10]
add path 'ugen*' mode 0660 group nut
add path 'uhid*' mode 0660 group nut
add path 'usb/*' mode 0660 group nut

# service devfs restart

Next – physically detach and then attach again the USB cable for the UPS.

Now start again the nut service.

# service nut start
Network UPS Tools - UPS driver controller 2.8.2
Network UPS Tools - Generic HID driver 0.53 (2.8.2)
USB communication driver (libusb 1.0) 0.47
Using subdriver: MGE HID 1.46
Starting nut.
Network UPS Tools upsd 2.8.2
fopen /var/db/nut/upsd.pid: No such file or directory
Could not find PID file '/var/db/nut/upsd.pid' to see if previous upsd instance is already running!
/usr/local/etc/nut/upsd.conf is world readable
listening on ::1 port 3493
listening on 127.0.0.1 port 3493
Connected to UPS [eaton3s]: usbhid-ups-eaton3s
Found 1 UPS defined in ups.conf

Lets check how these NUT daemon run.

# ps ax | grep -e COMMAND -e usbhid-ups -e upsd
  PID TT  STAT       TIME COMMAND
 7652  -  Ss      0:00.01 /usr/local/libexec/nut/usbhid-ups -a eaton3s
 7731  -  Ss      0:00.00 /usr/local/sbin/upsd
43135  0  S+      0:00.00 grep --color -e COMMAND -e usbhid-ups -e upsd

# cat /var/db/nut/upsd.pid /var/db/nut/usbhid-ups-eaton3s.pid
7731
7652

They seem to run properly just fine – lets check our UPS then.

# upsc eaton3s
battery.charge: 100
battery.charge.low: 20
battery.runtime: 3196
battery.type: PbAc
device.mfr: EATON
device.model: Eaton 3S 550 
device.serial: Blank
device.type: ups
driver.debug: 0
driver.flag.allow_killpower: 0
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: auto
driver.state: quiet
driver.version: 2.8.2
driver.version.data: MGE HID 1.46
driver.version.internal: 0.53
driver.version.usb: libusb-1.0.0 (API: 0x1000102)
input.transfer.high: 264
input.transfer.low: 184
outlet.1.desc: PowerShare Outlet 1
outlet.1.id: 1
outlet.1.status: on
outlet.1.switchable: no
outlet.desc: Main Outlet
outlet.id: 0
outlet.switchable: yes
output.frequency.nominal: 50
output.voltage: 230.0
output.voltage.nominal: 230
ups.beeper.status: disabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.firmware: 02.08.0010
ups.load: 6
ups.mfr: EATON
ups.model: Eaton 3S 550 
ups.power.nominal: 550
ups.productid: ffff
ups.realpower: 26
ups.serial: Blank
ups.status: OL
ups.timer.shutdown: -1
ups.timer.start: -1
ups.type: offline / line interactive
ups.vendorid: 0463

Recognized.

Supported.

We have all our parameters that we need.

Lets check what commands/options it has.

# upscmd -l eaton3s
Instant commands supported on UPS [eaton3s]:

beeper.disable - Disable the UPS beeper
beeper.enable - Enable the UPS beeper
beeper.mute - Temporarily mute the UPS beeper
beeper.off - Obsolete (use beeper.disable or beeper.mute)
beeper.on - Obsolete (use beeper.enable)
driver.killpower - Tell the driver daemon to initiate UPS shutdown; should be unlocked with driver.flag.allow_killpower option or variable setting
driver.reload - Reload running driver configuration from the file system (only works for changes in some options)
driver.reload-or-error - Reload running driver configuration from the file system (only works for changes in some options); return an error if something changed and could not be applied live (so the caller can restart it with new options)
driver.reload-or-exit - Reload running driver configuration from the file system (only works for changes in some options); exit the running driver if something changed and could not be applied live (so service management framework can restart it with new options)
load.off - Turn off the load immediately
load.off.delay - Turn off the load with a delay (seconds)
load.on - Turn on the load immediately
load.on.delay - Turn on the load with a delay (seconds)
shutdown.return - Turn off the load and return when power is back
shutdown.stayoff - Turn off the load and remain off
shutdown.stop - Stop a shutdown in progress

So I believe that ups.beeper.status is the option I seek.

# upsc eaton3s | grep -i beep
ups.beeper.status: enabled

Lets try to disable the beep on the UPS.

# upscmd eaton3s beeper.disable
Username (root): 
Password: 
OK
# upsc eaton3s | grep -i beep
ups.beeper.status: disabled

The beep sound on the Eaton 3S 550F 330W UPS seems to be disabled.

When the next power outage came I verified that indeed the Eaton 3S 550F 330W UPS does not beep anymore.

One may also want to configure NUT to do some actions like shutdown -p now when UPS capacity is less then 5% – but that is a topic for another article πŸ™‚

One thing to note – sometimes its better to reboot(8) after after /etc/devfs.rules file changes – there is not rule here … sometimes that helps.

Summary

Feel free to share your UPS configs and stories πŸ™‚

EOF