1 AUTHOR: Bryan Mason <bmason@bmason.com>
5 LICENSE: GNU Free Documentation License Version 1.2
6 Copyright (c) 2003-2004, Bryan Mason.
7 Permission is granted to copy, distribute and/or modify
8 this document under the terms of the GNU Free
9 Documentation License, Version 1.2 or any later version
10 published by the Free Software Foundation. A copy of the
11 license can be found at
12 http://www.gnu.org/copyleft/fdl.html.
14 SYNOPSIS: APCUPSD Power Protection from an APC UPS Connected via USB
16 ATTACHMENTS: Init script for starting apcupsd:
17 http://www.bmason.com/LFS/apcupsd/apcupsd
19 DESCRIPTION: This hint describes how to install some of the new
20 Uninterruptable Power Supplies (UPS's) from American
21 Power Conversion (APC) that use a Universal Serial Bus
22 (USB) interface to connect to the host.
24 PREREQUISITES: This hint assumes that you have already a working system
25 and are comfortable with configuring and re-compiling
26 the Linux kernel. Although this hint was written based
27 on LFS 3.3, it should work equally well on newer LFS
28 installations as well, although they have not been
37 2. Configuring the LFS Kernel for USB and HID Support
38 3. Installing apcupsd with USB Support
39 4. Configuring Apcupsd
40 5. Testing the Installation
43 8. Tested Configurations
50 John McSwain's hint, "Apcupsd power protection for your LFS
51 connected to an APC UPS via serial port" describes how to install an
52 Uninterruptable Power Supply (UPS) made by American Power Conversion
53 (APC) using apcupsd as the software interface between the UPS and
54 the LFS system. Apcupsd monitors the UPS and informs the system
55 when a power loss has occurred and can subsequently shutdown the
56 system if power is not restored within a predetermined time.
58 John's hint works fine for those UPS's that use a serial cable to
59 interface to the host computer, but many of APC's new UPS's use a
60 Universal Serial Bus (USB) hardware interface to connect to the
61 system that is being provided power by the UPS. Versions 3.9.4 and
62 later of apcupsd provide direct support for USB UPS's. This hint is
63 based on version 3.10.13 of apcupsd, the latest stable version of
64 apcupsd available at the time of writing.
66 Installation of a USB UPS consists of the following basic steps,
67 which are described in more detail below:
68 1) Configuring the LFS Kernel for USB and HID support
69 2) Installing apcupsd with USB support
70 3) Configuring apcupsd
71 3) Testing the installation
74 If you have any comments or corrections to be made to this document,
75 please send an e-mail message to the author at <bmason@bmason.com>.
78 2. Configuring the LFS Kernel for USB and HID Support
79 =====================================================
81 To enable the use of a USB UPS in Linux, not only USB support is
82 required, but also support for Human Interface Devices (HIDs). The
83 documentation on the apcupsd Web site states that Alan Cox's patch
84 are required to enable HID support. This may have been true on
85 older kernels, but HID support now seems to be an integral part of
86 kernel version 2.4.18 which was the version used in creating this
89 To enable USB and HID, make sure that the following items are
90 enabled either as a module or as part of the kernel. Generally it's
91 easier to install these as part of the kernel; otherwise the modules
92 will have to be loaded in the boot script and a delay will need to
93 be made so that the USB drivers can recognize the UPS.
95 Kernel options to be enabled:
97 - "Input Core Support" (CONFIG_INPUT)
98 - "Support for USB" (CONFIG_USB)
99 - "Preliminary USB File System" (CONFIG_USB_DEVICEFS)
100 - "USB Human Interface Device (full HID) support" (CONFIG_USB_HID)
101 - "/dev/hiddev raw HID device support" (CONFIG_USB_HIDDEV)
103 "UHCI (Intel PIIX4, VIA, ...) support" (CONFIG_USB_UHCI)
104 or "UHCI Alternate Driver (JE) support" (CONFIG_USB_UHCI_ALT)
105 or "OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support"
107 Which one of these last options is enabled will depend on the chip
108 set used in the system on which LFS is running. See your
109 motherboard documentation and the help system within menuconfig
110 for additional information.
112 After the kernel is configured, proceed with the normal process of
113 building and installing a new Linux kernel (make bzImage, make
114 modules, make modules_install, copy the bzImage file, etc.)
116 Strictly speaking, the "Preliminary USB File System" support isn't
117 required, but it should make debugging easier if there are problems.
120 3. Installing apcupsd with USB Support
121 ======================================
123 3.1 Review Existing Documentation
125 Before you install apcupsd, it might be a good idea to review the
126 documentation for the latest version of apcupsd on the apcupsd Web
127 site (<http://www.apcupsd.com/>). Specifically, the following
128 sections might be useful:
129 - Quick Start for Beginners
130 - Compiling and Installing
131 - Using Apcupsd with a USB UPS
133 Also, reviewing John McSwain's apcupsd hint is also probably a good
136 Much of what follows is based on the documentation listed above --
137 I've just put it in a convenient, easy to swallow format (I hope).
140 3.2 Download and Unpack Apcupsd
142 The source tarballs for apcupsd are located on SourceForge at
143 <http://sourceforge.net/projects/apcupsd/>
146 3.3 Create the HID Devices
148 After the source has been unpacked, use the "make-hiddev" script in
149 the "examples" directory of the apcupsd source tree to make the HID
150 devices. Make-hiddev performs the following commands:
153 mkdir -p /dev/usb/hid
154 mknod /dev/usb/hid/hiddev0 c 180 96
155 mknod /dev/usb/hid/hiddev1 c 180 97
156 mknod /dev/usb/hid/hiddev2 c 180 98
157 mknod /dev/usb/hid/hiddev3 c 180 99
158 mknod /dev/usb/hid/hiddev4 c 180 100
159 mknod /dev/usb/hid/hiddev5 c 180 101
160 mknod /dev/usb/hid/hiddev6 c 180 102
161 mknod /dev/usb/hid/hiddev7 c 180 103
162 mknod /dev/usb/hid/hiddev8 c 180 104
163 mknod /dev/usb/hid/hiddev9 c 180 105
164 mknod /dev/usb/hid/hiddev10 c 180 106
165 mknod /dev/usb/hid/hiddev11 c 180 107
166 mknod /dev/usb/hid/hiddev12 c 180 108
167 mknod /dev/usb/hid/hiddev13 c 180 109
168 mknod /dev/usb/hid/hiddev14 c 180 110
169 mknod /dev/usb/hid/hiddev15 c 180 111
171 After running make-hiddev, connect your UPS to your LFS system, and
172 then build and run the "hid-ups" test program to test the connection
173 between your system and the UPS.
175 If you compiled USB and/or HID support into modules, make sure that
176 you have loaded the modules before running hid-ups. The following
177 modules should be loaded:
181 - "usb-uhci" (or "usb-ohci" or whatever module you created)
183 To compile and execute hid-ups, execute the following commands
184 (substituting "<apcupsd-src>" with the directory to which you
185 unpacked the apcupsd source tarballs.
187 cd <apcupsd-src>/examples
191 If hid-ups is successful, the tail of the output from hid-ups should
192 look similar to the following:
195 Field 0, app UPS, phys ---
196 Usage 0, APCPanelTest = 0
199 Field 0, app UPS, phys ---
200 Usage 0, AudibleAlarmControl = 2
203 Field 0, app UPS, phys ---
204 Usage 0, APC860029_?????? = 34
207 Field 0, app UPS, phys ---
208 Usage 0, APC86002A_?????? = 0
210 Waiting for events ... (interrupt to exit)
212 Event: CommunicationLost = 0
214 Press Ctrl-C to exit hid-ups.
219 Now configure, compile, and install apcupsd by running the following
220 commands from the top of the source code tree:
222 ./configure --prefix=/usr --sbindir=/sbin \
223 --with-serial-dev=/dev/usb/hid/hiddev[0-9] \
224 --with-upstype=usb --with-upscable=usb --enable-usb \
225 --enable-pthreads --enable-powerflute &&
229 Below are descriptions of the options passed to the configure
232 --with-serial-dev=/dev/usb/hid/hiddev[0-9]: This is not a typo, and
233 should be entered exactly as shown. This syntax allows apcupsd to
234 search all the USB devices to find the UPS.
236 --with-upstype=usb: This tells apcupsd to default to a USB UPS. This
237 option can be changed at runtime by modifying apcupsd's
240 --with-upscable=usb: This tells apcupsd to default to a USB cable.
241 This option can be changed at runtime by modifying apcupsd's
244 --enable-usb: This enables the USB support in apcupsd.
246 --enable-pthreads: This option enables pthreads support causing
247 apcupsd to be built as a threaded program rather than forking to
248 create separate processes. This should cause apcupsd to be more
249 efficient with memory and resources. This is not strictly needed
250 for USB support, but is a good idea.
252 --enable-powerflute: This enables the building of powerflute, which
253 is an ncurses-based program that can be used to monitor the UPS.
254 This is not strictly need for USB support or even to build apcupsd,
255 but it could be a useful program.
257 Additional information on features that can be enabled through use
258 of the configure utility can be viewed by executing
262 Executing these commands will put the following files in the
263 following directories:
272 Configuration and Script Files
273 Location: /etc/apcupsd
285 Location: /usr/share/man/man8
288 4. Configuring Apcupsd
289 ======================
291 The apcupsd configuration file is located by default at
292 /etc/apcupsd/apcupsd.conf. There shouldn't be much of a need to
293 change anything in this file, since most of the important settings
294 have already been specified during the compilation of apcupsd in
297 The only thing that might be a good idea is to modify the behavior
298 of apcupsd and syslogd so that apcupsd events are sent to their own
299 file, /var/log/apcupsd.log. To do this, modify the following line in
302 From: #FACILITY local0
305 Then add the following lines to /etc/syslog.conf:
307 # Logging for apcupsd
308 local1.* -/var/log/apcupsd.log
310 If the "local1" facility is already being used by another program,
311 then change "local1" in the examples above to "local2" or another
314 After this is done, syslogd needs to be reloaded by executing the
317 /etc/rc.d/init.d/sysklogd reload
319 5. Testing the Installation
320 ===========================
324 The first step in testing is to run the apcupsd program itself.
325 Load the USB modules (if not compiled directly into the kernel) by
332 (The last command may need to be "modprobe usb-ohci") if you've
333 compiled kernel support for an OHCI compliant USB controller instead
334 of UHCI compliant one.)
336 Wait for apcupsd to configure itself and establish contact with the
337 UPS, and then execute
339 ps fax | grep apcupsd
341 The output should look something like
343 8525 ? SN 0:00 /sbin/apcupsd
344 8527 ? SN 0:00 \_ /sbin/apcupsd
345 8528 ? SN 0:00 \_ /sbin/apcupsd
346 8529 ? SN 0:00 \_ /sbin/apcupsd
350 4492 ? S 0:00 apcmain
351 4496 ? S 0:00 \_ apcser
352 4497 ? S 0:00 \_ apcnis
354 if you did not use the "--enable-pthreads" option in configure.
356 Next, take a look at the contents of the apcupsd log file by
359 tail /var/log/apcupsd.log
361 The result should be something similar to the following:
363 May 24 13:49:56 linux apcupsd[8217]: apcupsd 3.10.13 \
364 (16 April 2004) unknown startup succeeded
366 If apcupsd generates an error code and then exits, see the
367 "Troubleshooting Your Installation" section of the apcupsd
368 documentation on the apcupsd Web site (<http://www.apcupsd.com/>)
369 for information on possible sources of problems.
372 5.2 Getting UPS status
374 Once apcupsd is successfully loaded, the next step is to get status
375 from the UPS. To do this, execute
379 The result should be similar to the following:
382 DATE : Mon May 24 13:50:28 PDT 2004
385 VERSION : 3.10.13 (16 April 2004) unknown
388 MODEL : Back-UPS RS 1000
390 STARTTIME: Mon May 24 13:49:50 PDT 2004
394 LOADPCT : 18.0 Percent Load Capacity
395 BCHARGE : 100.0 Percent
396 TIMELEFT : 50.1 Minutes
397 MBATTCHG : 10 Percent
398 MINTIMEL : 10 Minutes
400 LOTRANS : 097.0 Volts
401 HITRANS : 138.0 Volts
409 STATFLAG : 0x02000008 Status Flag
411 SERIALNO : JB0241034799
412 BATTDATE : 2001-09-25
414 FIRMWARE : .g2 .D USB FW:g2
415 APCMODEL : Back-UPS RS 1000
416 END APC : Mon May 24 13:50:55 PDT 2004
422 6.1 Creating the boot script
424 The following boot script will start, stop, restart, etc. apcupsd.
425 It is based on the LFS boot script template
426 (/etc/rc.d/init.d/template) and the file apcupsd in the
427 platforms/unknown directory of the apcupsd source tree.
429 --------------------------------------------------------------------
431 # Begin /etc/rc.d/init.d/apcupsd
433 # Based on sysklogd script from LFS-3.1 and earlier.
434 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
435 # Apcupsd version written by Bryan Mason - bmason@bmason.com
437 source /etc/sysconfig/rc
442 # Comment the following lines if the USB and HID
443 # drivers were built into the kernel
444 # Use "modprobe usb-ohci" instead of "modprobe usb-uhci"
445 # if you have an OHCI compliant USB controller.
447 echo "Installing modules for USB and HID..."
452 echo "Starting APC UPS Daemon (apcupsd)..."
453 rm -f /etc/apcupsd/powerfail
455 loadproc /sbin/apcupsd
459 echo "Stopping APC UPS Daemon (apcupsd)..."
460 killproc /sbin/apcupsd
462 # Comment the following lines if the USB and HID
463 # drivers were built into the kernel
464 # Replace "usb-ohci" with "usb-uhci"
465 # if you have an OHCI compliant USB controller.
467 echo "Removing modules for USB and HID..."
468 rmmod usb-uhci hid input usbcore
471 # Sometimes killproc can't kill apcupsd, which
472 # interrupts the shutdown process.
473 # That isn't good. So lets make sure to always
474 # exit with a status of 0.
480 echo "Reloading APC UPS Daemon (apcupsd)..."
481 reloadproc /sbin/apcupsd
491 /sbin/apcaccess status
492 statusproc /sbin/apcupsd
496 echo "Usage: $0 {start|stop|reload|restart|status}"
502 # End /etc/rc.d/init.d/apcupsd
503 --------------------------------------------------------------------
505 The commands to load the USB kernel modules in the script can
506 probably be removed entirely if you're running hotplug. I don't use
507 hotplug, so I'm not sure about this. If anybody would like to
508 comment on this one way or another, please contact me and I'll add
509 the information into this document.
511 This file can be made by copying /etc/rc.d/init.d/template to
512 /etc/rc.d/init.d/apcupsd, made from scratch, or be downloaded from
513 <http://www.bmason.com/LFS/apcupsd/apcupsd>.
516 6.2 Creating the links for the boot script
518 Apcupsd should be started as soon as possible during the boot
519 process, right after sysklogd is started. Since sysklogd uses S10,
520 apcupsd can be started at S15 or S20. Apcupsd should also be one of
521 the last things to be stopped, right before sysklogd is stopped.
522 Create the symbolic links by executing the following commands:
526 ln -s ../init.d/apcupsd K35apcupsd &&
528 ln -s ../init.d/apcupsd K75apcupsd &&
530 ln -s ../init.d/apcupsd S15apcupsd &&
532 ln -s ../init.d/apcupsd S15apcupsd &&
534 ln -s ../init.d/apcupsd S15apcupsd &&
536 ln -s ../init.d/apcupsd S15apcupsd &&
538 ln -s ../init.d/apcupsd K35apcupsd
540 Of course, if you've renumbered your boot scripts, then you'll need
541 to link the apcupsd boot script accordingly.
544 6.3 Creating the UPS Powerdown Script
546 Normally, the last thing that needs to happen before the system
547 shuts down is to power off the UPS. Unfortunately, one of the known
548 limitations of apcupsd interfacing to a USB UPS is that the
549 "--killpower" option to apcupsd doesn't work, which means that it is
550 not possible to power off a USB UPS. Although the apcupsd
551 documentation states that the UPS should shut itself down one to two
552 minutes after the system, I did not observe this in my testing. In
553 my case, the UPS continued to supply power to the computer until the
554 batteries drained to a critically low level. Of course, this wasn't
555 a problem because the system had already been shut down.
561 Many tests that should be run on the system before the installation
562 is considered complete and stable. The "Testing Apcupsd" section of
563 the documentation on the apcupsd Web site
564 (<http://www.apcupsd.com/>) contains a list of such tests. The first
565 three tests were performed in Section 6 above. Briefly, the rest of
566 the test sequence runs as follows:
568 - Remove the USB cable from the UPS to make sure communications
570 - Modify some of the scripts used by apcupsd so that they are
571 "safe" (i.e. they won't actually shut down the system) and
572 disconnect the UPS from utility power.
573 - Perform a full shutdown test, but do not allow the UPS to
575 - Perform a full shutdown test, allowing the UPS to cut power to
579 8. Tested Configurations
580 ========================
582 The following configuration has been tested and is fully functional
583 after following the instructions in this hint:
585 * APC Back-UPS XS 1000
586 Note: Apcupsd reports this as a Back-UPS RS 1000
587 * APC Back-UPS LS 700 on Slackware 9.1
588 * APC Back-UPS RS 1000 on Slackware 9.1
589 * APC Back-UPS XS 1000 on SuSE 8.2
591 If you have successfully installed another APC USB UPS on your LFS
592 system, please send an e-mail message to <bmason@bmason.com> so I
593 can add your model number to the above list.
598 The installation of my USB UPS went very smoothly. I didn't have to
599 do much troubleshooting, so I don't have any troubleshooting steps
600 to report. If you experience problems with your installation and
601 have a way to overcome them, please send an e-mail message to
602 <bmason@bmason.com> with your experience, and I'll add it to this
607 * John M. McSwain <jmcswain@infoave.net> for providing the original
609 * Artur Kedzierski <Artur@Kedzierski.org> for providing information
610 on the Back-UPS LS 700 and Back-UPS RS 1000.
611 * Brett Delmage <Brett.Delmage@twobikes.ottawa.on.ca> for providing
612 information on the Back-UPS XS 1000 running on SuSE 8.2.
619 * Modified to conform to new hint format. Updated some links.
621 * Added information on Back-UPS LS 700 and RS 1000 on Slackware 9.1.
623 * Updated for apcupsd version 3.10.13.
624 * Added more detail on what files would be created and where they
626 * Fixed a couple of mistakes and oversights.
627 * Added information on Back-UPS XS 1000 on SuSE 8.2