MikeL's FreeBSD howto - Add a UPS

This is basically a checklist of how to install an Uninteruptable power supply to be monitored by the system. The intent is not to cover everything in detail, merely to point you to each of the tasks that must be performed.


[20240425]
I've recently done some updating to all this. I can't believe how much trouble I put into this back in 2000 (see below) -- I had completely forgotten all that.

My setup: in my home office I have a rack server, and a desktop plugged into an APC BackUPS Pro 1300. FreeBSD on the server, Win 11 on the desktop. There is also a WiFi and router. The server is a massive power hog, and is only a backup for my primary Co-Lo'ed elsewhares, so I want it to shutdown fairly soon after powerfail. I want the router and WiFi to remain available as long as possible so that my cellphone etc. can use the DSL, assuming of course that it's still up.

I'm now using apcupsd on all systems. The BBU USB cable goes into the desktop as it remains powered longest, UPSCABLE usb, UPSTYPE usb, DEVICE [empty] -- I have it set to power down early (TIMEOUT 4) minutes as this machine takes a significant amount of power which would drain the battery for no real reason. If I were to be at the desktop during that powerfail, this would be sufficient time for me to close up what I was doing. This machine is configured to provide outgoing service (NISIP 0.0.0.0 and NISPORT 3551).

The server is configured to read the desktop for it's BBU info (UPSCABLE ether, UPSTYPE net amd DEVICE [desktopfqdn]. It's set for shutdown very early (TIMEOUT 2) mins. Note that the FreeBSD server will shut down to HALT, but not actually power down by default, making all this useless. To fix this, you must edit /usr/local/etc/apcupsd/apccontrol, find and replace the shutdown -h with shutdown -p.

In the basement where the phone line comes into the house, I have a small APC BBU with only the CenturyLink ActionTec DSL modem plugged into it. No computers, no BBU control wire - it just goes until it runs out of battery. The assumption is that the DSL modem will resume safely when the power returns. This takes very little power and will run for many hours.

In another location, I have another desktop and a Raspberry Pi plugged into another APC Pro 1300. The desktop runs a weather station, but the weather station can handle saving it's own data for about a month, so this desktop is non-critical. It's set to (UPSCABLE ether, UPSTYPE net, DEVICE [rPifqdn]), and to shutdown early, namely TIMEOUT 3. The rPi runs my driveway monitor, thus is considered critical and should run as long as possible. Thus the BBU cable goes into the rPi (UPSCABLE usb, UPSTYPE usb, DEVICE [empty]), which is set to shut down at 5% (BATTERYLEVEL 5) or MINUTES 2. Note that in the rPi, you do not want to change the shutdown command from -h to -p as you want this to resume upon power return, and there's no consequence once we've shutdown and the battery finally reaches exhausted.

I also have a mechanism for sending myself txt messages. A URL with info goes to the rPi, which runs a custom service which then uses Twilio to send to my phone. The service expects JSON encoded data, hence on the Unix boxes, I added the following to each of the scripts in /etc/apcupsd/:
curl -d '{ "file":"'"$MSG"'" }' http://[mylocalserverurl].
On the Windows boxes, in the C:\apcupsd\etc\apccontrol.bat file, I've updated the POPUP= line to:
curl -d "{ \"file\":\"%command%\" }" http://[mylocalserverurl]


[20000608]
There are several different packages to do this. I tried upsd (directions below), but it doesn't work with my "dumb" UPS (APC 500). upsmon actually has some documentation, but it sounds like it won't either, so I won't even try. The latter mentions pwrfaild, but I can't find anything about it. Somewhere on the web I found reference to bkpupsd, so now I'm trying it (many gory details below).
NOTE!

I had to make a special cable to adapt my APC Back-UPS 500 work with this program. A DB-9 male to female (male is UPS side), with all pins just passing through, except:
pin 4 is left open on both sides, and pins 6 and 7 are shorted. The reason is that the UPS is asserting DTR (pin 4) and DSR. DTR is supposed to be driven by the computer end, thus it is being held low by the computer. This in turn, is holding DSR down as well, thus it is left open.

I also had to modify the program -- immediately before the line ioctl(fd, TIOCMBIS, &dtr_bit);, I had to add dtr_bit = -1; this is the first one inside the while(1) loop. Also, the line else if(lstatus & TIOCM_RNG) { gets the TIOCM_RNG replaced with 0x100.
Diff listing:

90a91
> dtr_bit = -1;
112c113
>          else if(lstatus & 0x100 /*TIOCM_RNG*/) {
---
<          else if(lstatus & TIOCM_RNG) {
Protocol notes:
While making the cable work, I had a breakout box plugged into the serial line. I observed the following:
Copyright © 1995-2024 Mike Lempriere (running on host bayanus)