|
Apple Mac Mini
How-to
|
Configuring a UPS
Having any computer connected to a
UPS
is generally a good idea,
but it's virtually a necessity for a server that runs 24/7.
In addition to a UPS simply supplying back-up power,
it can also signal your computer to shut itself down cleanly
in the event of a sustained power-loss.
Choosing a UPS
To determine the size of a UPS that you need,
you need to know two things:
-
The total power requirements
specified in either watts (W) or volt-amps (VA).
-
The desired run-time on batter power.
Power requirements
In addition to the two Minis,
I also want both the DSL modem and the router
to be connected to the UPS
so the Minis retain network connectivity
to send me a text message when the UPS
has been operating on battery power
for at least 5 minutes.
I also want the wireless base station
to be connected to the UPS
so I can log in from my PowerBook.
Therefore, the power requirements for my set-up are:
| Device |
Watts |
| Mac Mini (85W x 2) |
170 |
| DSL modem |
30 |
| Router/switch |
20 |
| Wireless base station |
20 |
| Total: |
240 |
|
Pulsar Evolution 1500VA
|
Run-time
For a desktop computer,
having a UPS last only 5 minutes on battery power is sufficient
because all it's supposed to allow
is for you to shut down the computer cleanly.
For a server running 24/7, however,
a UPS has to last longer because it will often be the case that
you're not there to shut the computer down
and bring it back up once power has been restored.
I therefore decided that I wanted my UPS to last about an hour
on battery power.
That should hopefully be sufficient to outlast any power-loss.
Once that the power requirements and battery-power run-time are known,
you can use the "UPS selector" tools
found on many UPS manufacturers' web sites
to help you select the right size UPS.
Make & model
As for choosing the make and model of a UPS,
you need to ensure that it:
-
Has a USB port to communicate with the Mini.
(Historically, UPSs only had DB-9 serial ports.)
-
Works under Linux (preferably, is well-supported under Linux).
I therefore chose
MGE UPS Systems
for the manufacturer and the
Pulsar Evolution
1500VA for the specific model of UPS.
Not only does the Pulsar Evolution have a USB port,
but all of MGE's UPSs are well supported under Linux.
Not only that, but MGE actively contributes their own
open source
and have their own
how-to
web page for Linux.
Configuring the software
The software that commonly used is
Network UPS Tools (NUT).
For a Debian system, you can install the packages by doing:
apt-get install nut nut-cgi nut-usb
The configuration files for NUT are mostly in the
/etc/nut directory
and should have the following owners, groups, and permissions:
-rw-r--r-- 1 root root hosts.conf
-rw-r--r-- 1 root root ups.conf
-rw-r----- 1 root nut upsd.conf
-rw-r----- 1 root nut upsd.users
-rw-r----- 1 root nut upsmon.conf
-rw-r--r-- 1 root root upssched.conf
-rw-r--r-- 1 root root upsset.conf
-rw-r----- 1 root www upsstats-single.html
-
The files, their purpose, and contents are:
-
- ups.conf
-
This file names the UPS
and specifies how to communicate with it:
[pulsar_evolution]
driver = newhidups
port = auto
- hosts.conf
-
This file specifies name of the UPS to monitor
as well as a descriptive label:
MONITOR pulsar_evolution@mini "Pulsar Evolution"
- upsd.conf
-
This file specifies the access control, i.e.,
which users from which machines may monitor the UPS:
ACL home_net 10.0.1.0/24
ACCEPT home_net
REJECT all
The label home_net can be anything you want
and specifies that only a machine on my home 10.0.1 network
may access the UPS.
- upsd.users
-
This file specifies the users that may access the UPS:
[admin]
password = master-password
allowfrom = home_net
actions = SET
instcmds = ALL
[monuser]
password = user-password
allowfrom = home_net
upsmon master
There should be (at least) two users:
an admin user and a monitoring user
that has only read-only privileges.
- upsmon.conf
-
This file is used to configure upsmon
(the UPS monitoring daemon):
RUN_AS_USER nut
MONITOR pulsar_evolution@mini 1 monuser user-password master
MINSUPPLIES 1
DEADTIME 15
FINALDELAY 5
HOSTSYNC 15
NOCOMMWARNTIME 300
NOTIFYCMD /sbin/upssched
POLLFREQ 5
POLLFREQALERT 5
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
SHUTDOWNCMD "/sbin/shutdown -h +0"
NOTIFYMSG COMMBAD "UPS communications lost"
NOTIFYMSG COMMOK "UPS communications established"
NOTIFYMSG FSD "UPS being shut down by master"
NOTIFYMSG LOWBATT "UPS has a low battery"
NOTIFYMSG NOCOMM "UPS unavailable"
NOTIFYMSG ONBATT "UPS on battery power"
NOTIFYMSG ONLINE "UPS on line power"
NOTIFYMSG REPLBATT "UPS battery needs replacement"
NOTIFYMSG SHUTDOWN "NUT shutting system down"
NOTIFYFLAG COMMBAD SYSLOG+EXEC
NOTIFYFLAG COMMOK SYSLOG+EXEC
NOTIFYFLAG FSD SYSLOG+EXEC
NOTIFYFLAG LOWBATT SYSLOG+EXEC
NOTIFYFLAG NOCOMM SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG REPLBATT SYSLOG+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+EXEC
The second line specifies the UPS to monitor,
the monitoring user monuser and password
that must match what's specified in upsd.users.
The items
COMBAD, COMMOK, LOWBATT, etc.,
are all the states that the UPS and the NUT software can be in.
NOTIFYMSG allows a more-readable message to be specified
when a state-change occurs
and NOTIFYFLAGS specifies what to do when a state-change
occurs.
The values for the latter are all SYSLOG+EXEC
that means
(1) log the message via the syslog
mechanism
and
(2) execute the command specified by NOTIFYCMD.
The reason the values are all SYSLOG+EXEC
is because I want to defer what to do upon a state-change
to the upssched program for all state-changes
so there's only one place where this is specified.
I think NOTIFYFLAG introduces an unnecessary level
of indirection and flexibility.
- upssched.conf
-
This file specifies what upssched should do when
executed when a UPS or NUT software state-change occurs:
CMDSCRIPT /usr/local/sbin/upssched-cmd
PIPEFN /var/run/nut/upssched.pipe
LOCKFN /var/run/nut/upssched.lock
AT COMMBAD * START-TIMER COMMBAD 10
AT COMMOK * CANCEL-TIMER COMMBAD COMMOK
AT FSD * EXECUTE FSD
AT LOWBATT * EXECUTE LOWBATT
AT NOCOMM * START-TIMER COMMBAD 10
AT ONBATT * START-TIMER ONBATT 300
AT ONLINE * CANCEL-TIMER ONBATT ONLINE
AT REPLBATT * EXECUTE REPLBATT
AT SHUTDOWN * EXECUTE SHUTDOWN
CMDSCRIPT specifies the script to execute
when appropriate.
Since the Debian package didn't come with one,
I wrote one:
upssched-cmd.
The AT lines specify what to do for a particular state.
(The * means "for any UPS.")
Timers can be used to prevent immediate action.
For example,
if the communication between NUT and the UPS is lost
(COMMBAD or NOCOMM),
a "COMMBAD" timer is started
and will last 10 seconds.
Timers can have any names you want.
I just thought it was simpler and consistent
to make timers and states have the same name.
If communication is restored (COMMOK)
in under 10 seconds,
then the COMMBAD timer is cancelled
and no other action is taken,
i.e., upssched-cmd is never called.
If communication is not restored in under 10 seconds,
the COMMBAD timer will expire
and upssched-cmd will be called
with the single command-line argument of the timer name.
If communication is subsequently restored,
upssched-cmd will be called with the single command-line
argument that is the second argument to CANCEL-TIMER,
in this case COMMOK.
Again for simplicity and consistency,
I'm using the state name as the argument.
Similarly, a timer of 5 minutes is started
when the UPS switches to battery power (ONBATT)
and back to line power (ONLINE).
The upssched-cmd
script is straight-forward and is easily configurable
as to which UPS/NUT states notify you by what means.
- upsstats-single.html
-
This file is an HTML template for use with the
upsstats.cgi script
that renders a
very nice web page
showing the status of a UPS.
I tweaked the HTML file more to my liking
(made it XHTML, added auto-refresh, and a few layout
changes).
Here is my version.
Yes, despite appearances,
the formatting of the @ lines is correct
since they must start in column 1.
There is one additional configuration file
/etc/default/nut that contains:
START_UPSD=yes
START_UPSMON=yes
If more than one computer is being powered by the same UPS,
then all the computers that are not directly connected to it via a USB
cable should be configured as:
START_UPSD=no
START_UPSMON=yes
|