Google Site SearchFN Site Search FN Blog Login FN Blog Login
Site Navigation:
 
 

How to use UPS with nut

by Kazutoshi Morioka on Feb 17, 2004

This memo describes how to use APC's SmartUPS with nut (Network UPS tools) package found in the Fedora Core.

Installing nut package

Network UPS tools is comprehensive UPS managing and monitoring daemon can be used with various UPS. In the Fedora Core (and also in the Red Hat Linux) nut is included as two packages, "nut" and "nut-client". Both is requred. You can install nut and nut-client packages with yum as like:

[morioka@myserver morioka]$ su
Password:
[root@myserver morioka]# yum -y install nut nut-client
Gathering header information file(s) from server(s)
Server: Fedora Core 1 - i386 - Base
Server: Fedora Core 1 - i386 - Released Updates
Finding updated packages
Downloading needed headers
Resolving dependencies
Dependencies resolved
I will do the following:
[install: nut 1.4.0-3.i386]
[install: nut-client 1.4.0-3.i386]
Getting nut-1.4.0-3.i386.rpm
nut-1.4.0-3.i386.rpm      100% |=========================| 773 kB    00:00
Getting nut-client-1.4.0-3.i386.rpm
nut-client-1.4.0-3.i386.r 100% |=========================|  86 kB    00:00
Running test transaction:
Test transaction complete, Success!
nut-client 100 % done 1/2
nut 100 % done 2/2
Installed:  nut 1.4.0-3.i386 nut-client 1.4.0-3.i386
Transaction(s) Complete
[root@myserver morioka]#
Although this memo is using nut package, if you think to use SmartUPS, it is better that buy PowerChute software from APC Inc. PowerChute will offer easy installation and nice UI. When you order UPS from APC Inc, you must check the type of UPS-cable. If you order wrong cable, you cannot use PowerChute. If this happen, remember nut package. This will help you.

Configuring nut

Nut's configuration files are placed in the /etc/ups directory.

  • ups.conf - settings for UPS-specific driver
  • upsd.conf - settings for main UPS daemon
  • upsd.users - access control file for UPS daemon
  • upsmon.conf - settings for UPS monitoring daemon
  • upssched.conf - settings for upssched daemon
Addition to these, /etc/sysconfig/ups is also provided in the Fedora Core RPM pakcage. You can specify some command line options for upsd in /etc/sysconfig/ups .
We do not use upssched daemon. So, we will not touch upssched.conf.

Configuring /etc/sysconfig/ups

This is settings for SmartUPS attached to serial port 1 (/dev/ttyS0). I specify changes in italic font.

# If the UPS is locally attached set it to "yes"
SERVER=yes
# Model of the UPS (filename to call for it, without path)
# Example - one of
#	apcsmart	- APC SMartUPS and similar
#	fentonups	- Fenton UPS
#	optiups
#	bestups
#	genericups
#	ups-trust425+625
#  upsdrvctl
# You MUST change this, or set SERVER to "no"
# To support multiple drivers, set MODEL=upsdrvctl
MODEL=apcsmart
# UPS device - needed if UPS is locally attached
DEVICE=/dev/ttyS0
# Any options to pass to $MODEL
# ex. for my TrippLite UPS, use 
#	OPTIONS="-t 5"
OPTIONS=
# Any options to pass to upsd
UPSD_OPTIONS=
#
# [End]

Fix permissions

RPM's default permission of configuration files are looking strange for me.

[root@myserver morioka]# ls -l /etc/ups
合計 12
-r--r--r--    1 root     root         3682  9月 25 09:27 ups.conf
-r--r--r--    1 root     root         1495  9月 25 09:27 upsd.conf
-r--------    1 root     root         2215  9月 25 09:27 upsd.users
-r--------    1 nut      nut         11046  9月 25 09:27 upsmon.conf
-r--------    1 nut      nut          3884  9月 25 09:27 upssched.conf
Not only looking strange, it won't work. This may be a reason why peoples fail to use nut. Change permissions as below:
[root@myserver morioka]# cd /etc/ups
[root@myserver ups]# chown root:nut ups*
[root@myserver ups]# chmod 640 ups*
[root@myserver ups]# ls -l
合計 28
-rw-r-----    1 root     nut          3740  2月  5 11:14 ups.conf
-rw-r-----    1 root     nut          1496  2月  5 11:03 upsd.conf
-rw-r-----    1 root     nut          2284  2月  5 11:08 upsd.users
-rw-r-----    1 root     nut         11046  9月 25 09:27 upsmon.conf
-rw-r-----    1 root     nut          3884  9月 25 09:27 upssched.conf

Configure /etc/ups/ups.conf

UPS-specific driver settings must go into /etc/ups/ups.conf. What driver supports what type of UPS is described in the document /usr/share/doc/nut-1.4.0/docs/driver.list. APC Inc's Smart-UPS was supported with apcsmart or newapc driver. We will use apcsmart driver this time. You can see settings for apcsmart-driver with command:

[root@myserver morioka]# man apcsmart
Actual settings are below (I added bold lines):
#
# To find out if your driver supports any extra settings, start it with
# with the -h option and/or read the driver's documentation.
[myups]
       driver = apcsmart
       port = /dev/ttyS0
       sdtype = 0
myups is name of UPS. you can choose any name.

Configure /etc/ups/upsd.conf

We won't use networking features of nut package. So, you needs no changes for upsd.conf. Default settings are below:

ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
 
ACCESS grant monitor localhost
ACCESS deny all all

Configure /etc/ups/upsd.users

/etc/ups/upsd.users allow or deny accesses to upsd daemon from clients (upsmon daemon, upsc command, ...). We must allow upsmon daemon to connect to upsd. This is 4 line settings below:

# The matching MONITOR line in your upsmon.conf would look like this:
#
# MONITOR myups@myhost 1 monuser pass master   (or slave)
[monuser]
       password = Y0mJre1o
       allowfrom = localhost
       upsmon master
  • [monuser] is a label for access from upsmon daemon. We can set any name.
  • password = line will specify the password. This password is not used by human. Only specified in configuration files.
  • allowfrom = line will specify ACL name to allow access. Note: This "localhost" is not localhost as a hostname, but a ACL name defined in /etc/ups/upsd.conf:
    	ACL localhost 127.0.0.1/32
    	
  • upsmon master line is a upsmon specific setting. If your upsd will work master-mode (normally so), you must specify "master" as argument of this line.
If you must create some passwords, you can use mkpasswd command. This mkpasswd command is included in the GNU expect package. Fedora Core's mkpasswd command is patched to use /dev/urandom to get random seed. But original mkpasswd in the GNU expect tarball use time value as random seed, so it may create weak passwords.

Configure /etc/ups/upsmon.conf

/etc/ups/upsmon.conf is settings for upsmon, UPS monitoring daemon.

#
# MONITOR myups@bigserver 1 monmaster blah master
# MONITOR su700@server.example.com 1 upsmon secretpass slave
MONITOR myups@localhost 1 monuser Y0mJre1o master
 
# --------------------------------------------------------------------------
# MINSUPPLIES 
Only one MONITOR line is needed. This will specify name of UPS ("myups"), hostname in which upsd will run ("localhost"), label of access ("monuser"), password ("Y0mJre1o"), and "master" or "slave" (normaly "master"). These settings are collesponds to settings in /etc/ups/upsd.users.

Using upsd

Start upsd

After all configurations are made, start upsd as:

[root@myserver morioka]# /etc/init.d/ups start
apcsmart start:                                          [  OK  ]
upsd start:                                              [  OK  ]
UPS monitor (master) start:                              [  OK  ]
[root@myserver morioka]# grep ups /var/log/messages
	snip
Feb  5 12:54:08 myserver ups: apcsmart start succeeded
Feb  5 12:54:08 myserver upsd[2415]: Connected to UPS [myups]: apcsmart-ttyS0
Feb  5 12:54:08 myserver upsd: Network UPS Tools upsd 1.4.0
Feb  5 12:54:08 myserver upsd: Synchronizing...
Feb  5 12:54:08 myserver upsd: Connected to UPS [myups]: apcsmart-ttyS0
Feb  5 12:54:09 myserver upsd: .
Feb  5 12:54:10 myserver upsd[2416]: Startup successful
Feb  5 12:54:10 myserver upsd: done
Feb  5 12:54:10 myserver ups: upsd start succeeded
Feb  5 12:54:10 myserver upsmon[2420]: Startup successful
Feb  5 12:54:10 myserver upsd[2416]: Connection from 127.0.0.1
Feb  5 12:54:10 myserver upsd[2416]: Client monuser@127.0.0.1 logged into UPS [myups]
Feb  5 12:54:10 myserver upsmon: UPS: myups@localhost (master) (power value 1)
Feb  5 12:54:10 myserver upsmon: Using power down flag file /etc/killpower
Feb  5 12:54:10 myserver upsmon:
Feb  5 12:54:10 myserver ups: upsmon起動 succeeded
[root@myserver morioka]# ps ax|grep ups
 2416 ?        S      0:00 /usr/sbin/upsd
 2420 ?        S      0:00 /usr/sbin/upsmon
 2421 ?        S      0:00 /usr/sbin/upsmon
 2433 pts/3    S      0:00 grep ups
You can see that two upsmon is running, but this is normal behavior.

dig UPS status with upsc

The upsc command gives you some UPS status. You can see battery charge state, voltage, AC-status, and etc.

[root@myserver morioka]# upsc myups@localhost
battery.alarm.threshold: 0
battery.charge: 100.0
battery.charge.restart: 00
battery.date: 11/28/00
battery.voltage: 27.47
driver.name: apcsmart
driver.version: 1.4.0
driver.version.internal: 0.72
input.frequency: 60.00
input.sensitivity: H
input.transfer.high: 110
input.transfer.low: 090
input.voltage: 097.5
output.voltage: 097.5
ups.delay.shutdown: 020
ups.delay.start: 000
ups.id: UPS_IDEN
ups.load: 009.3
ups.mfr: APC
ups.model: SMART-UPS 500
ups.serial: NS0049130658
ups.status: OL
ups.temperature: 036.4
[root@myserver morioka]#

some useful links