Typo
[linux_from_scratch_hints.git] / OLD / apcupsd-serial.txt
blobb83f232ca6d4931577dc2864cf38042494fa9753
1 TITLE:          Apcupsd-serial
2 LFS VERSION:    any 
3 AUTHOR:         John McSwain <jmcswain@infoave.net>
5 SYNOPSIS:
6         Installing Apcupsd to protect an LFS system using APC UPS connected
7         via serial port.    
9 HINT:
10 version 1.1 (02/19/2003)
12 ========================
13 TABLE OF CONTENTS
14 ========================
15 1 Introduction
16 2 Changelog
17 3 Software
18 4 Installation
19   4.1 Generic
20   4.2 LFS specific
21       4.2.1 Boot script
22       4.2.2 Poweroff script
23       4.2.3 Symlink the scripts
24 5 Configuration      
25 6 Conclusion
28 =================
29 1. Introduction
30 =================
32 Apcupsd is useful for controlling American Power Conversion's (APC)
33 uninterruptiple power supplies (UPS).  Apcupsd monitors the UPS and during a
34 power loss, informs the system users of the failure, and if power is not 
35 restored, safely shuts down the system.  The Apcupsd manual (available on line
36 at http://www.sibbald.com/apcupsd/manual/index.html or with the software)
37 provides excellent instructions on installing and configuring the software.
38 The configure script can identify several standard linux distributions and make
39 the correct installation. However, as LFS is by design not standard this hint
40 provides the information to protect an LFS system with an APC UPS connected
41 via a serial connection using Apcupsd software.
43 If you are using an APC UPS that connects via USB please see the hint by
44 Bryan Mason <http://cvs.linuxfromscratch.org/index.cgi/hints/apcupsd-usb.txt>.
47 The installation of Apcupsd is mostly straightforward until "make install" is
48 completed. Then the LFS user will see the following series of messages:
50 "Unknown distribution
51 You have to manually install apcupsd boot script and
52 halt script for clean emergency shutdown.
53 Please contribute your distribution install to apcupsd team.
54 I'm sorry: you are on your own."
56 The purpose of this hint is to provide one method of accomplishing the above
57 actions to get Apcupsd up and running on the LFS "unknown" distribution.
59 =================
60 2. Changelog
61 =================
63  1.0 Original hint (06/27/01)
65  1.1 Updated to current script location (/etc/rc.d/init.d/), two digit symlinks,
66     software download location and latest version.      
68 =================
69 3. Software
70 =================
72 The Apcupsd software can currently be found at sourceforge:
74 http://download.sourceforge.net/apcupsd/
76 As of this writing the latest stable release is Apcupsd-3.8.6.
79 ===================
80 4. Installation
81 ===================
83 Obtain the source and unpack it in a suitable place such as /usr/src/.
84 Compiler optimizations can be used with Apcupsd.  See Optimization.txt hint
85 and the Apcupsd manual for more information.
87 ===================
88 4.1 Generic
89 ===================
90 Run the following command:
92 ./configure --prefix=/usr --sbindir=/sbin
94 This is a basic installation.  If you have a smartups and wish to have a web
95 interface to the APC unit's status from your web server see the Apcupsd manual.
96 You will probably want to run the above commands with additions:
98 ./configure --prefix=/usr --sbindir=/sbin \
99  --with-cgi-bin=/home/httpd/cgi-bin --enable-cgi
101 Now run:
103 make &&
104 make install
106 ===================
107 4.2 LFS specific
108 ===================
110 At the end of the make install you will get the messages listed above in the
111 introduction.  A bootscript and proper halt script must be manually
112 installed.
114 ==================
115 4.2.1 Bootscript
116 ==================
118 Use the template script in /etc/rc.d/init.d as a guide to make the boot script.
120 cd /etc/rc.d/init.d
121 cp template apcupsd
123 Now edit the apcupsd file to make the following bootscript:
125 #!/bin/sh
126 # Begin /etc/rc.d/init.d/apcupsd
128 # S20 in /etc/rc{2,3,4,5}.d and K95 /etc/rc{0,1,6}.d
130 source /etc/sysconfig/rc
131 source $rc_functions
133 case "$1" in
134         start)
135                 # House keeping if this were a restart from powerfail
136                 rm -f /etc/apcupsd/powerfail
137                 rm -f /etc/nologin
138                 # Start apcupsd
139                 echo -n "Starting apcupsd power management ..."
140                 loadproc /sbin/apcupsd
141                 ;;
143         stop)
144                 echo -n "Stopping apcupsd power management..."
145                 killproc apcupsd
146                 ;;
148         reload)
149                 echo -n "Reloading apcupsd power management ..."
150                 reloadproc apcupsd
151                 ;;
153         restart)
154                 $0 stop
155                 sleep 1
156                 $0 start
157                 ;;
159         status)
160                 statusproc apcupsd
161                 ;;
163         *)
164                 echo "Usage: $0 {start|stop|reload|restart|status}"
165                 exit 1
166         ;;
168 esac
170 # End /etc/rc.d/init.d/apcupsd
173 =====================
174 4.2.2 Poweroff script
175 =====================
177 This poweroff script is needed to shutdown the UPS after the system has halted.
178 (Note: Depending on the UPS this could take a minute or two).  Thus when the 
179 power returns the UPS will come back on and the system will power up (providing
180 your atx bios supports powerup).  
182 Apcupsd for most distributions modifies the existing halt script.  Rather than
183 that route we are making a separate script called UPSdown.
185 Using a text editor create UPSdown as follows in /etc/rc.d/init.d:
187 #!/bin/sh
188 # Begin /etc/rc.d/init.d/UPSdown
190 # Script to shutdown UPS after computer shutdown
192 # Symlink in rc0.d after umounting filesystems
195 # See if this is a powerfail situation
196 if [ -f /etc/apcupsd/powerfail ]; then
197         echo
198         echo "APCUPSD will now power off the UPS"
199         echo
200         /etc/apcupsd/apccontrol killpower       
201         echo
202         echo "Verify the UPS shuts down or turn off the system"
203         echo
206 # End /etc/rc.d/init.d/UPSdown
209 =========================
210 4.2.3 Symlink the scripts
211 =========================
212 The apcupsd daemon should be started fairly soon in the boot cycle to provide
213 protection.  Using the current two digit symlinks, S20 for my system seems
214 appropriate.  Use your own judgement here.
216 Stopping the daemon should occur fairly late.  I use K95.
218 The UPSdown script should be run immediately prior to the halt script.  If
219 halt is K99 then UPSdown would be S98.
221 Run the following:
223 cd /etc/rc.d/init.d &&
224 chmod 755 apcupsd UPSdown &&
225 cd ../rc0.d &&
226 ln -s ../init.d/apcupsd K95apcupsd &&
227 ln -s ../init.d/UPSdown K98UPSdown &&
228 cd ../rc1.d &&
229 ln -s ../init.d/apcupsd K95apcupsd &&
230 cd ../rc2.d &&
231 ln -s ../init.d/apcupsd S20apcupsd &&
232 cd ../rc3.d &&
233 ln -s ../init.d/apcupsd S20apcupsd &&
234 cd ../rc4.d &&
235 ln -s ../init.d/apcupsd S20apcupsd &&
236 cd ../rc5.d &&
237 ln -s ../init.d/apcupsd S20apcupsd &&
238 cd ../rc6.d &&
239 ln -s ../init.d/apcupsd K95apcupsd
242 ================
243 5. Configuration
244 ================
246 Our generic configure in  4.1 above placed the configuration file in
247 /etc/apcupsd.  This file is called apcupsd.conf.  Please consult the apcupsd
248 manual to determine the settings for your system and APC model UPS.
250 ================
251 6. Conclusion
252 ==============
253 The above steps were an attempt to have you quickly provide APC UPS power
254 protection to your system using Apcupsd software.  The software allows the
255 individual user a lot of options depending on his needs and desires.  For
256 example I use the cgi feature to be able to see the status of my UPS from a
257 browser.  I use the notification feature to mail the electric company that I
258 have loss power.  These and other features along with a description of the
259 workings of Apcupsd are fully described in the Apcupsd manual.