Typo
[linux_from_scratch_hints.git] / OLD / apcupsd.txt
blobaa7c80ea096240a38c36cd2c82ef8229a4cf41f7
1 TITLE:          Apcupsd
2 LFS VERSION:    any 
3 AUTHOR:         John McSwain <jmcswain@infoave.net>
5 SYNOPSIS:
6         Installing Apcupsd to protect an LFS system using APC UPS.    
8 HINT:
9 version 1.0 (06/27/2001)
11 ========================
12 TABLE OF CONTENTS
13 ========================
14 1 Introduction
15 2 Software
16 3 Installation
17   3.1 Generic
18   3.2 LFS specific
19       3.2.1 Boot script
20       3.2.2 Poweroff script
21       3.2.3 Symlink the scripts
22 4 Configuration      
23 5 Conclusion
26 =================
27 1. Introduction
28 =================
30 Apcupsd is useful for controlling American Power Conversion's (APC)
31 uninterruptiple power supplies (UPS).  Apcupsd monitors the UPS and during a
32 power loss, informs the system users of the failure, and if power is not 
33 restored, safely shuts down the system.  The Apcupsd manual (available on line
34 at http://www.sibbald.com/apcupsd/manual/index.html or with the software)
35 provides excellent instructions on installing and configuring the software.
36 The configure script can identify several standard linux distributions and make
37 the correct installation. However, as LFS is by design not standard this hint
38 provides the information to protect an LFS system with an APC UPS using
39 Apcupsd.
41 The installation of Apcupsd is mostly straightforward until "make install" is
42 completed. Then the LFS user will see the following series of messages:
44 "Unknown distribution
45 You have to manually install apcupsd boot script and
46 halt script for clean emergency shutdown.
47 Please contribute your distribution install to apcupsd team.
48 I'm sorry: you are on your own."
50 The purpose of this hint is to provide one method of accomplishing the above
51 actions to get Apcupsd up and running on the LFS "unknown" distribution.
53 =================
54 2. Software
55 =================
57 The Apcupsd software can be found at these sites:
59 http://www.oasi.gpa.it/riccardo/linux/apcupsd/
60 http://www.sibbald.com/apcupsd/
61 ftp://ftp.oasi.gpa.it/pub/apcupsd/
63 As of this writing the latest stable release is Apcupsd-3.8.1.  However 
64 Apcupsd-3.8.2Beta14 has been used with no problems by this author.
67 ===================
68 3. Installation
69 ===================
71 Obtain the source and unpack it in a suitable place such as /usr/src/.
72 Compiler optimizations can be used with Apcupsd.  See Optimization.txt hint
73 and the Apcupsd manual for more information.
75 ===================
76 3.1 Generic
77 ===================
78 Run the following command:
80 ./configure --prefix=/usr --sbindir=/sbin
82 This is a basic installation.  If you have a smartups and wish to have a web
83 interface to the APC unit's status from your web server see the Apcupsd manual.
84 You will probably want to run the above commands with additions:
86 ./configure --prefix=/usr --sbindir=/sbin \
87  --with-cgi-bin=/home/httpd/cgi-bin --enable-cgi
89 Now run:
91 make &&
92 make install
94 ===================
95 3.2 LFS specific
96 ===================
98 At the end of the make install you will get the messages listed above in the
99 introduction.  A bootscript and proper halt script must be manually
100 installed.
102 ==================
103 3.2.1 Bootscript
104 ==================
106 Use the template script in /etc/init.d as a guide to make the boot script.
108 cd /etc/init.d
109 cp template apcupsd
111 Now edit the apcupsd file to make the following bootscript:
113 #!/bin/sh
114 # Begin /etc/init.d/apcupsd
116 # S200 in /etc/rc{2,3,4,5}.d and K990 /etc/rc{0,1,6}.d
118 source /etc/init.d/functions
120 case "$1" in
121         start)
122                 # House keeping if this were a restart from powerfail
123                 rm -f /etc/apcupsd/powerfail
124                 rm -f /etc/nologin
125                 # Start apcupsd
126                 echo -n "Starting apcupsd power management ..."
127                 loadproc /sbin/apcupsd
128                 ;;
130         stop)
131                 echo -n "Stopping apcupsd power management..."
132                 killproc apcupsd
133                 ;;
135         reload)
136                 echo -n "Reloading apcupsd power management ..."
137                 reloadproc apcupsd
138                 ;;
140         restart)
141                 $0 stop
142                 sleep 1
143                 $0 start
144                 ;;
146         status)
147                 statusproc apcupsd
148                 ;;
150         *)
151                 echo "Usage: $0 {start|stop|reload|restart|status}"
152                 exit 1
153         ;;
155 esac
157 # End /etc/init.d/apcupsd
160 =====================
161 3.2.2 Poweroff script
162 =====================
164 This poweroff script is needed to shutdown the UPS after the system has halted.
165 (Note: Depending on the UPS this could take a minute or two).  Thus when the 
166 power returns the UPS will come back on and the system will power up (providing
167 your atx bios supports powerup).  
169 Apcupsd for most distributions modifies the existing halt script.  Rather than
170 that route we are making a separate script called UPSdown.
172 Using a text editor create UPSdown as follows in /etc/init.d:
174 #!/bin/sh
175 # Begin /etc/init.d/UPSdown
177 # Script to shutdown UPS after computer shutdown
179 # Symlink in rc0.d after umounting filesystems
182 # See if this is a powerfail situation
183 if [ -f /etc/apcupsd/powerfail ]; then
184         echo
185         echo "APCUPSD will now power off the UPS"
186         echo
187         /etc/apcupsd/apccontrol killpower       
188         echo
189         echo "Verify the UPS shuts down or turn off the system"
190         echo
193 # End /etc/init.d/UPSdown
196 =========================
197 3.2.3 Symlink the scripts
198 =========================
199 The apcupsd daemon should be started fairly soon in the boot cycle to provide
200 protection.  Using three digit symlinks, S200 for my system seems appropriate.
201 Use your own judgement here.
203 Stopping the daemon should occur fairly late.  I use K990.
205 The UPSdown script should be run immediately prior to the halt script.  If
206 halt is S999 then UPSdown would be S998.
208 Run the following:
210 cd /etc/init.d &&
211 chmod 754 apcupsd UPSdown &&
212 cd ../rc0.d &&
213 ln -s ../init.d/apcupsd K990apcupsd &&
214 ln -s ../init.d/UPSdown S998UPSdown &&
215 cd ../rc1.d &&
216 ln -s ../init.d/apcupsd K990apcupsd &&
217 cd ../rc2.d &&
218 ln -s ../init.d/apcupsd S200apcupsd &&
219 cd ../rc3.d &&
220 ln -s ../init.d/apcupsd S200apcupsd &&
221 cd ../rc4.d &&
222 ln -s ../init.d/apcupsd S200apcupsd &&
223 cd ../rc5.d &&
224 ln -s ../init.d/apcupsd S200apcupsd &&
225 cd ../rc6.d &&
226 ln -s ../init.d/apcupsd K990apcupsd
229 ================
230 4. Configuration
231 ================
233 Our generic configure in  3.1 above placed the configuration file in
234 /etc/apcupsd.  This file is called apcupsd.conf.  Pleae consult the apcupsd
235 manual to determine the settings for your system and APC model UPS.
237 ================
238 5. Conclusion
239 ==============
240 The above steps were an attempt to have you quickly provide APC UPS power
241 protection to your system using Apcupsd software.  The software allows the
242 individual user a lot of options depending on his needs and desires.  For
243 example I use the cgi feature to be able to see the status of my UPS from a
244 browser.  I use the notification feature to mail the electric company that I
245 have loss power.  These and other features along with a description of the
246 workings of Apcupsd are fully described in the Apcupsd manual.