Lately, the power grid appears to have gone to hell. An Uninterruptible Power Supply(UPS) just isn't an optional piece of equipment anymore -- it's not for nothing that very decent UPS has a computer interface port. If your computer is connected to the port, and the software is set up, the UPS can tell your computer to safely shut down before the battery runs out.

Got a couple of machines sharing a UPS? In today's How-To, we'll show you how to use your network to shut down all of the computers plugged into it and keep your precious data safe.


In order to set up your UPS to run two (or more) machines, you'll have to use a network connection to tell the other machines what to do. Step one: don't forget to connect your network hub or switch to your UPS! For today's how-to, we'll have a machine running Ubuntu Linux and a machine running Windows XP. The UPS is connected to the Linux box via serial (or USB) cable. The Linux box will supply UPS status information to the Windows machine. When we're done, both machines can safely shutdown during an extended power outage.

Newer APC units seem to be including USB cables. Most of the older APC UPS units (like our handy BackUPS 500) have a serial port. If you need to build a new serial cable like we did, a quick visit to pinouts.ru may provide the info you need to make it.

If you just have a single Windows machine, you can use XP's basic UPS functionality. (We always find that installing less software is a good thing.) Just open up the power control panel and click on the UPS tab. Configuration is simple, but not very flexible -- even a little annoying in that it doesn't include a method to test your UPS without shutting down the machine. We'll cover setting up a network client on the Windows box later.

Installing Network UPS Tools under Ubuntu Linux is easy. Open the synaptic package manager (inder the System->Administration menu) and search for 'nut'. Select the package for installation and click on Apply.

To get things going, we have to create and edit five configuration files on our Linux box.

Edit /etc/default/nut with your favorite editor (example: sudo vi /etc/default/nut). Change the options to match above (i.e. no to yes).
Create and edit /etc/nut/ups.conf - (sudo vi /etc/nut/ups.conf)
The configuration is pretty simple. The compatibility list is a good place to start. Check the compatibility list to find out what driver/upstype to specify. For our APC BackUPS, it just the generic UPS driver, and we used serial port ttyS0.
It should look like this:
[deskups]
driver=genericups
port=/dev/ttyS0
upstype=2

Once that's configured, you can run upsdrvctl start to see if your UPS driver is working.
We had to do a quick chmod 777 /dev/ttyS0 command to get things going. If you have two serial ports, you may need to try using /dev/ttyS1 instead.

Create and edit /etc/nut/upsd.conf. (sudo vi /etc/nut/upsd.conf)
Our remote Windows box is located at ip address 10.0.0.57, change it to suit.
If you want to allow your local network, put in the network address (i.e. 10.0.0.0/24)
ACL all 0.0.0.0/0
ACL remote 10.0.0.57/32
ACL localhost 127.0.0.1/32

ACCEPT localhost
ACCEPT remote
REJECT all


Create /etc/nut/upsd.users. Put the following:
[monuser]
password = USERPASS
allowfrom = local
upsmon master

Create /etc/nut/upsmon.conf, add the following:
MONITOR ups-a-name-o@localhost 1 monuser USERPASS master
SHUTDOWNCMD "/sbin/shutdown -h +0"
replace MASTERPASS with your master password.

Get a copy of the latest WinNUT here. Download and install it in the usual fashion. At the end of the installer, the WinNut configuration tool will start.

Click the Edit button next to the configuration file path.
In the first blank line, add the following
MONITOR deskups@10.0.0.10 1 upsmon USERPASS slave
deskups is the name of the UPS.
10.0.0.10 is the ip address of our Linux box.
The 1 says that 1 UPS must be running for the box to stay up.
USERPASS is the password from the upsd.users file.
slave tells the box to shut down ASAP so the master can shutdown first.
Save the file and close notepad.
Go back to the configuration tool and hit Apply and start WinNUT.

For testing, just push and hold the button to the Test position. You'll get several notifications on the Linux box, and a pop-up should appear on the Windows machine. Once everything is working happily, open the WinNUT configuration tool and set it to run as a service that starts up automatically. The Ubuntu services should start up thanks to the changes made to /etc/default/nut.

If you have a pair of Windows boxes you'd like to do this with, that's tough. Ok, we do have a few tricks: we've had good luck connecting GPS units up to multiple hosts serial ports just by wiring the ports together. You might be able to do a similar hack, but we haven't tested that one. So don't come crying to us if you break it.

Otherwise, that should be that. Let the rolling brownouts and blackouts begin!

0 Comments