Update Hint Apcupsd power protection for your LFS connected to an APC UPS via serial port

John McSwain john at lakemcgregor.com
Wed Jan 4 05:00:41 PST 2006


 Below is the updated text for hint "Apcupsd power protection for your 
LFS connected to an APC UPS via serial port".  As a bz2 attachment are 
the revised startup scripts to replace those currently residing in 
http://www.linuxfromscratch.org/hints/downloads/attachments/apcupsd-serial/.

Thanks,
John McSwain
http://www.lakemcgregor.com/

-------------- next part --------------TITLE:  Apcupsd-serialAUTHOR: 
Hints Author and Owner John M. McSwain <jmcswain at infoave.net>DATE: 
2006-01-04LICENSE: GNU Free Documentation License Version 1.2Copyright 
(c)  2003 John M. McSwainPermission is granted to copy, distribute 
and/or modify this documentunder the terms of the GNU Free Documentation 
License, Version 1.2or any later version published by the Free Software 
Foundation. A copy of the license can be found at 
http://www.gnu.org/copyleft/fdl.html.SYNOPSIS: Apcupsd power protection 
for your LFS connected to an APC UPS via serial port. 
DESCRIPTION:This hint describes the installation of Apcupsd software on 
an LFS basedcomputer protected by an American Power Conversion (APC) 
uinterruptible powersupply connected via serial cable.  The normal 
software installation analyzesthe sytem to determine a standard linux 
distribution so that scripts may beinstalled to their proper place. 
Because LFS is nonstandard the installation is not completed and left to 
the user.  This hint describes the steps needed tocomplete the software 
installation on an LFS system.PREREQUISITES:This hint will work on any 
LFS system although the bootscripts may need minormodifications.  This 
is especially true of older LFS systems where the bootscripts were NOT 
in the /etc/rc.d/init.d directory.HINT:========================TABLE OF 
CONTENTS========================1 Introduction2 Software3 Installation 
3.1 Generic  3.2 LFS specific      3.2.1 Boot script      3.2.2 Poweroff 
script      3.2.3 Symlink the scripts4 Configuration      5 
Conclusion=================1. Introduction=================Apcupsd is 
useful for controlling American Power Conversion's (APC)uninterruptiple 
power supplies (UPS).  Apcupsd monitors the UPS and during apower loss, 
informs the system users of the failure, and if power is not restored, 
safely shuts down the system.  The Apcupsd manual (available on lineat 
http://www.sibbald.com/apcupsd/manual/index.html or with the 
software)provides excellent instructions on installing and configuring 
the software.The configure script can identify several standard linux 
distributions and makethe correct installation. However, as LFS is by 
design not standard this hintprovides the information to protect an LFS 
system with an APC UPS connectedvia a serial connection using Apcupsd 
software.If you are using an APC UPS that connects via USB please see 
the hint byBryan Mason.The installation of Apcupsd is mostly 
straightforward until "make install" iscompleted. Then the LFS user will 
see the following series of messages:"Unknown distributionYou have to 
manually install apcupsd boot script andhalt script for clean emergency 
shutdown.Please contribute your distribution install to apcupsd team.I'm 
sorry: you are on your own."The purpose of this hint is to provide one 
method of accomplishing the aboveactions to get Apcupsd up and running 
on the LFS "unknown" distribution.=================2. 
Software=================The Apcupsd software can currently be found at 
sourceforge:http://prdownloads.sourceforge.net/apcupsd/As of this 
writing the latest stable release is 
Apcupsd-3.10.18.===================3. 
Installation===================Obtain the source and unpack it in a 
suitable place such as /usr/src/.Compiler optimizations can be used with 
Apcupsd.  See Optimization.txt hintand the Apcupsd manual for more 
information.===================3.1 Generic===================Run the 
following command:./configure --prefix=/usr --sbindir=/sbinThis is a 
basic installation.  If you have a Smartups and wish to have a 
webinterface to the APC unit's status from your web server see the 
Apcupsd manual.You will probably want to run the above commands with 
additions:./configure --prefix=/usr --sbindir=/sbin 
\ --with-cgi-bin=/srv/www/cgi-bin --enable-cgiNow run:make &&make 
install===================3.2 LFS specific===================At the end 
of the make install you will get the messages listed above in 
theintroduction.  A bootscript and proper halt script must be 
manuallyinstalled.==================3.2.1 Bootscript==================My 
suggested scripts can be found 
here:http://www.linuxfromscratch.org/hints/downloads/attachments/apcupsd-serial/You 
may wish to make your own using the template script located 
in/etc/rc.d/init.d as a guide.cd /etc/rc.d/init.dcp template apcupsdNow 
edit the apcupsd file.  Under "start)" have the following lines: 
start)                boot_mesg "Starting apcupsd power management..." 
# House keeping if this were a restart from powerfail 
               rm -f /etc/apcupsd/powerfail                rm -f 
/etc/nologin                loadproc /sbin/apcupsd                ;; 
stop)                boot_mesg "Stopping apcupsd power management..." 
killproc /sbin/apcupsd                ;;=====================3.2.2 
Poweroff script=====================The poweroff script is needed to 
shutdown the UPS after the system has halted.(Note: Depending on the UPS 
this could take a minute or two).  Thus when the power returns the UPS 
will come back on and the system will power up (providingyour atx bios 
supports powerup).  Apcupsd for most distributions modifies the existing 
halt script.  Rather thanthat route we are making a separate script 
called UPSdown.You may use my script mentioned above, or you can easily 
make your own using atext editor and place it in 
/etc/rc.d/init.d:#!/bin/sh# Begin /etc/rc.d/init.d/UPSdown## Script to 
shutdown UPS after computer shutdown## Symlink in rc0.d after umounting 
filesystems### See if this is a powerfail situationif [ -f 
/etc/apcupsd/powerfail ]; then        echo        echo "APCUPSD will now 
power off the UPS"        echo        /etc/apcupsd/apccontrol killpower 
echo        echo "Verify the UPS shuts down or turn off the system" 
echofi## End /etc/rc.d/init.d/UPSdown=========================3.2.3 
Symlink the scripts=========================The apcupsd daemon should be 
started fairly soon in the boot cycle to provideprotection.  Using the 
current two digit symlinks, S30 for my system seemsappropriate.  Use 
your own judgement here.I stop the daemon rather late in run levels 
rc1.d and rc6.d, K98.The UPSdown script should be run immediately prior 
to the halt script.  Ifhalt is K99 then UPSdown would be K98.Run the 
following:cd /etc/rc.d/init.d &&chmod 755 apcupsd UPSdown &&cd ../rc0.d 
&&ln -s ../init.d/UPSdown K98UPSdown &&cd ../rc1.d &&ln -s 
../init.d/apcupsd K98apcupsd &&cd ../rc2.d &&ln -s ../init.d/apcupsd 
S30apcupsd &&cd ../rc3.d &&ln -s ../init.d/apcupsd S30apcupsd &&cd 
../rc4.d &&ln -s ../init.d/apcupsd S30apcupsd &&cd ../rc5.d &&ln -s 
../init.d/apcupsd S30apcupsd &&cd ../rc6.d &&ln -s ../init.d/apcupsd 
K98apcupsd================4. Configuration================Our generic 
configure in 3.1 above placed the configuration file in/etc/apcupsd. 
This file is called apcupsd.conf.  Please consult the apcupsdmanual to 
determine the settings for your system and APC model 
UPS.================6. Conclusion==============The above steps were an 
attempt to have you quickly provide APC UPS powerprotection to your 
system using Apcupsd software.  The software allows theindividual user a 
lot of options depending on his needs and desires.  Forexample I use the 
cgi feature to be able to see the status of my UPS from abrowser.  I use 
the notification feature to mail the electric company that Ihave loss 
power.  These and other features along with a description of theworkings 
of Apcupsd are fully described in the Apcupsd manual. 
CHANGELOG:[2001-06-27]  * Initial hint.[2003-02-19]    * Updated to 
current LFS script location (/etc/rc.d/init.d/).  * Use two digit 
symlinks versus three.  * Updated software download location and latest 
version.[2003-09-16]  * Format modified to meet new Hint Format 
requirements.[2005-01-04]  * Updated to apcupsd-3.10.18  * Modified 
download location for apcupsd  * Modified symlinks in run levels  * 
Fixed missing last two commands in section 3.2.3   * Updated apcupsd 
startup script to current LFS-6.1.1 style  * Changed cgi path in section 
3.1 configure command from old /home/httpd 



More information about the hints mailing list