\documentclass[letterpaper]{article}
\nonstopmode
\akai
\usepackage{linuxdoc-sgml}
\usepackage{qwertz}
\usepackage{url}
\usepackage[latin1]{inputenc}
\usepackage{t1enc}
\usepackage[english]{babel}
\usepackage{epsfig}
\usepackage{null}
\def\addbibtoc{
\addcontentsline{toc}{section}{\numberline{\mbox{}}\relax\bibname}
}%end-preamble
\setcounter{page}{1}
\title{ÖÐÎÄ UPS Howto}
\author{Harvey J. Stein, \onlynameurl{abel@netvision.net.il}, Berger Financial Research, Ltd.}
\date{v2.02, 31 March 1997}
\abstract{±¾ÎÄÄÜ°ïÖúÄú½« Linux ÏµÍ³Á¬½Óµ½²»¶ÏµçÏµÍ³ (uninterruptable power supply, UPS)...
Èç¹ûÐÒÔËµÄ»° ....
°æÈ¨ÉùÃ÷:
Copyright (c) 1994, 1995, 1996, 1997 by Harvey J. Stein.  You may use
this document as you see fit, as long as it remains intact.  In
particular, this notice (along with the contributions below) must
remain untouched.}


\begin{document}
\maketitle
\tableofcontents

\section{¼ò½é}



±¾ HOWTO ÎÄ¼þ°üº¬ÁËÈçºÎÁ¬½Ó UPS µ½Ö´ÐÐ Linux µÄµçÄÔÉÏ¡£
ÆäÏë·¨ÊÇÒÔÊÊµ±µÄ·½Ê½½«¶þÕßÏàÁ¬½Ó£¬Ê¹µÃ Linux 
¿ÉÒÔÔÚµçÔ´¶ÏµçÒÔ¼° UPS µÄµç³ØºÄ¹âÇ°°²È«µØ¹Ø»ú¡£

ÆäÖÐ»¹°üÀ¨ÁËÒ»Ð©¿É°ïÖúÄú½¨Á¢ÉÏÊöÁ¬ÏßµÄÈíÌå£¬ÒÔ¼°ÏêÊö¸ÃÁ¬ÏßµÄÔË×÷·½Ê½¡£
¼ÙÈçÄúÄÜÕÒµ½Ò»¸öÒÑÉè¶¨ºÃ¿ÉÒÔÊ¹ÓÃÄúµÄ UPS µÄÈíÌå£¬
ÔòááÕßµÄËµÃ÷¶ÔÄúÀ´ËµÍ¨³£ÊÇ²»ÐèÒªµÄ¡£·ñÔòµÄ»°£¬Äú±ØÐë×ÐÏ¸µØÔÄ¶ÁËü¡£

ÔÚÏàµ±µÄ³Ì¶ÈÉÏ±¾ÎÄ¼þÒÑ±ÈÆðÎÒÔÚÈýÄêÇ°Ëù×«Ð´µÄÔ­ÎÄ¶à³öÁËºÜ¶àÄÚÈÝ¡£
ËùÓÐµÄ»ù±¾×ÊÁÏ¶¼¿ÉÒÔÔÚ {\ttfamily SysVinit} ÖÐµÄ {\ttfamily powerd} man page ¡õÕÒµ½¡£
¾¡¹ÜÔÚÈýÄêÇ°ÓÐÈË¿ÉÄÜÎÞ·¨ÔÚÒ»°ãµÄ Linux Ì×¼þÖÐÕÒµ½ÕâÆª man page £¬
µ«ÎÒ²»ÏàÐÅ½ñáá»¹»áÔÙ·¢ÉúÕâÑùµÄÇé¿ö¡£

³ý´ËÖ®Íâ£¬µ±ÎÒµÚÒ»´Î×«Ð´ÕâÆª Howto £¬³ýÁË {\ttfamily powerd.c}
ÒÔÍâ²¢Ã»ÓÐÆäËûµÄÈíÌå¿ÉÒÔ×öÎª Linux/UPS Ö®¼äµÄ¹µÍ¨Óë¿ØÖÆ¡£
¶ø½ñÈÕÎÒÃÇÔò¿ÉÒÔÔÚ \nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups}{Sunsite's UPS directory}
ÏÂÕÒµ½Ò»´ó¶Ñ UPS ¿ØÖÆÈíÌå¡£

È»¶ø£¬ÊÜµ½ RedHat ¼´½«ÖØÐÂÓ¡ÖÆ Dr. Linux µÄ¼¤Àø£¬ÎÒÒ²¿ªÊ¼ÖØÐ´ÕâÆª UPS Hotwo ¡£
ÎªÊ²÷áÄØ? àÅ ....

\begin{itemize}
\item ÎÒÏë£¬¶îÍâµÄÒ»°ãÐÔ¸Å¹Û½«ÄÜÓÐÖúì¶ÁË½âÈçºÎ½« Linux ÏµÍ³Á¬ÉÏ UPS £¬
¼´Ê¹ËüÖ»ÊÇÁíÒ»·ÝÄÚÈÝÏàÍ¬µÄÎÄ¼þ¡£
\item ÕâÆª HOWTO ËãÊÇ¸÷ÖÖÌØÊâ UPS ×ÊÁÏµÄ´¢²Ø¿â --- 
ÔÚÕâ¶ùÓÐÐí¶àÉÐÎ´±»ÕûºÏÈëÒ»°ãÈíÌåÌ×¼þÖÐµÄ UPS ×ÊÑ¶¡£
\item ÕâÆª HOWTO °üº¬ÁËÒ»Ð©ÔÚÆäËûÎÄ¼þÖÐÕÒ²»µ½µÄ¶îÍâÏêÏ¸×ÊÁÏ¡£
\item Ò»Ð©¿ÉÒÔÔÚ \nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups}{Sunsite's UPS directory} 
ÕÒµÃµ½µÄ UPS ÈíÌåËÆºõËµÃ÷ÎÄ¼þ¶¼ÉÙµÃ¿ÉÁ¯¡£
ÄúÒ²ÐíÐèÒªÏÈÔÄ¡õ±¾ÎÄÒÔÁË½âÈçºÎÊ¹ÓÃËûÃÇ¡£
\item ÏÖÔÚÕâ¼þÊÂËÆºõÒÑÓÐÁË×Ô¼ºµÄÉúÃüÁË¡£µ±Ò»Æª HOWTO 
ÎÄ¼þÒò¶øµ®ÉúÊ±ÊÂÊµ¾Í¸ü¼ÓÃ÷ÏÔÁË¡£ÁíÒ»¸ö±È½Ï²»Ã÷ÏÔµÄÊÂÊµÊÇµ±Ëü±ØÐëÉÏ´²Ë¯¾õÊ±¡£

(Òë×¢: ÕâÒ»¾äÐ¦»°ÎÒ¿´²»¶®À²! °¦! ·­µÃºÃÀÃ ....)
\end{itemize}





\subsection{ÓÐ¹±Ï×µÄÈËÃÇ}



ÎÒÓÀÔ¶¶¼»á¸Ð¼¤ÄÇÐ©Ôø¾­¸øÎÒ°ïÖú¡¢¸øÎÒ½¨Òé¡¢ÒÔ¼°¸øÎÒÌØÊâµÄ UPS ×ÊÁÏµÄÈËÃÇ¡£
ÆäÖÐ°üÀ¨ÁË:

\begin{itemize}
\item Hennus Bergman
(\onlynameurl{hennus@sky.owl.nl})
\item Charli
(\onlynameurl{mefistos@impsat1.com.ar})
\item Ciro Cattuto
(\onlynameurl{Ciro Cattuto})
\item Nick Christenson
(\onlynameurl{npc@minotaur.jpl.nasa.gov})
\item Lam Dang
(\onlynameurl{angit@netcom.com})
\item Markus Eiden
(\onlynameurl{Markus@eiden.de})
\item Dan Fandrich
(\onlynameurl{dan@fch.wimsey.bc.ca})
\item Ben Galliart
(\onlynameurl{bgallia@orion.it.luc.edu})
\item Danny ter Haar
(\onlynameurl{dth@cistron.nl})
\item Christian G. Holtje
(\onlynameurl{docwhat@uiuc.edu})
\item Raymond A. Ingles
(\onlynameurl{inglesra@frc.com})
\item Peter Kammer
(\onlynameurl{pkammer@ics.uci.edu})
\item Marek Michalkiewicz
(\onlynameurl{ind43@sun1000.ci.pwr.wroc.pl})
\item Jim Ockers
(\onlynameurl{ockers@umr.edu})
 
\item Evgeny Stambulchik
(\onlynameurl{fnevgeny@plasma-gate.weizmann.ac.il})
\item Clive A. Stubbings
(\onlynameurl{cas@vjet.demon.co.uk})
\item Miquel van Smoorenburg
(\onlynameurl{miquels@cistron.nl})
\item Slavik Terletsky
(\onlynameurl{ts@polynet.lviv.ua})
\item Tom Webster
(\onlynameurl{webster@kaiwan.com})
\end{itemize}


Çë×¢ÒâÏÂ·½µÄ email µØÖ·ÊÇ×Ôµç×ÓÐÅ¼þÖÐ½ÚÂ¼ÏÂÀ´µÄ£¬ËüÃÇÒ²Ðí»á¹ýÆÚ¡£
¶øÉÏ·½µÄ email µØÖ·¿ÉÄÜÒ²»á¹ýÆÚ£¬µ«ÓÐÐ©ÊÇ±ÈÆðÏÂ·½»¹ÒªÐÂµÄ¡£

³ý´ËÖ®Íâ£¬Èç¹ûÒòÎÒµÄÊèºö¶øÔÚÉÏ±íÖÐÂ©µôÈÎºÎÒ»Î»ÓÐ¹±Ï×ÕßµÄ»°£¬ÎÒÕæµÄºÜ±§Ç¸¡£
ÇëÄú email ¸øÎÒ£¬ÎÒ»á½«ÄúµÄÃû×Ö¼ÓÉÏÈ¥¡£






\subsection{ÇëÌØ±ð×¢Òâ}

ÎÒÕæµÄÎÞ·¨±£Ö¤ÕâÐ©¶«¶«¶ÔÄú»áÓÐÐ§¡£Á¬½á UPS µ½µçÄÔÉÏÊÇÒ»¼þÏàµ±ÓÐ¼¼ÇÉµÄ¹¤×÷¡£
ÆäÖÐÖ®Ò»»ò¶þÕß¶¼ÓÐ¿ÉÄÜ»áÉÕµô¡¢±¬Õ¨¡¢Öø»ð¡¢»òÕßÊÇÒý·¢µÚÈý´ÎÊÀ½ç´óÕ½¡£
³ý´ËÖ®Íâ£¬ÎÒÖ»ÓÐ¶Ô Advice 1200 A UPS£¬ÒÔ¼° 5kva Best Ferrups ÓÐÖ±½ÓµÄ¾­Ñé£¬
¶øÇÒÎÒÒ²²»ÐèÒª×Ô¼º×öÒ»ÌõÑ¶ºÅÏß¡£ËùÒÔ£¬Çë×¢Òâ! ¾¡¿ÉÄÜµØÊÕ¼¯ÄúµÄ UPS µÄËùÓÐ×ÊÑ¶¡£
ÇëÏÈ¿¼ÂÇÇå³þ£¬²»ÒªËæ±ãÏàÐÅÈÎºÎÄúÔÚ±¾ÎÄÖÐ»òÆäËûµØ·½Ëù¶Áµ½µÄÄÚÈÝ¡£

ÁíÒ»·½Ãæ£¬ÎÒÕý¾¡¿ÉÄÜµØÊÕ¼¯ËùÓÐÊ¹ÎÒµÄ UPS ¿ÉÒÔ¹¤×÷µÄ·½·¨£¬
ÆäÖÐÓÐºÜ¶à²»ÊÇÀ´×ÔÖÆÔìÉÌµÄ×ÊÑ¶£¬ËùÐÒÒ²Ã»ÓÐÉÕµôÈÎºÎ¶«Î÷£¬ËùÒÔÕâÐ©¶¼ÊÇ¿ÉÄÜµÄ¡£






\subsection{ÆäËûµÄÎÄ¼þ}

±¾ÎÄ²¢Ã»ÓÐ°üº¬ËùÓÐ UPS µÄÒ»°ãÌØÐÔÓëÄÜÁ¦¡£ÈçÄúÐèÒªÕâÀàÐÍµÄ×ÊÑ¶£¬Äã¿ÉÒÔ¿´¿´
\nameurl{ftp://navigator.jpl.nasa.gov/pub/doc/faq/UPS.faq}{The UPS FAQ}¡£
ÕâÆªÎÄ¼þÍ¬Ê±Ò²¿ÉÒÔÔÚ \onlynameurl{ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/answers/UPS-faq}
ÖÐÕÒµ½¡£ËüÊÇÓÉ Nick Christenson (\onlynameurl{npc@minotaur.jpl.nasa.gov})
ËùÎ¬»¤µÄ£¬µ«¿´ÆðÀ´ºÃÏñ×Ô´Ó 1995 ÄêÒÔáá¾ÍÃ»ÓÐÔÙÖØÐ´ÁË¡£Èç¹ûÄúÒª email ¸øËû£¬
ËûÏ£ÍûÄú¿ÉÒÔÔÚÐÅ¼þµÄ Subject ÄÇÒ»ÐÐ·ÅÈë {\ttfamily UPS} »ò {\ttfamily UPS FAQ} 
»òÆäËûÏà¹ØµÄ´Ê¾ä¡£

ÓÐÐíÐí¶à¶àµÄ UPS ÖÆÔìÉÌÔÚÍøÂ·ÖÐÃÈÑ¿¡£
ÆäÖÐÓÐÐ©È·ÊµÔÚËûÃÇµÄÍøÒ³ÖÐÌá¹©ÁËÓÐÓÃµÄ×ÊÑ¶¡£Äú¿ÉÒÔÔÚ
\nameurl{http://www.upssystems.uk.com/upsdir.html}{The UPS Directory} ÖÐÕÒµ½ÕâÐ© UPS 
ÖÆÔìÉÌµÄÍøÒ³¼ò±í¡£¸ÃÍøÕ¾Ò²°üº¬ÁË
\nameurl{http://www.upssystems.uk.com/upsfaqs.html}{UPS FAQ}
ÕâÆªÎÄ¼þ¡£






\section{Çë×¢ÒâÒÑ¹ýÊ±µÄ×ÊÑ¶}

ÎÒ¸Õ¸Õ·¢ÏÖµ×ÏÂÓÐÒ»Ð©×ÊÁÏÒÑ¾­¹ýÊ±ÁË¡£ÆäÖÐÀ´×Ô
\nameurl{http://sunsite.unc.edu/pub/Linux/system/daemons/init/sysvinit-2.64.tar.gz}{the latest sysvinit package}
µÄ {\ttfamily init} daemon ±ÈÆðÎÒËùÄÜÃèÊöµÄ»¹Òª¼òÂª¡£
¾¡¹Ü¿´ÆðÀ´Ä¿Ç°µÄ°æ±¾Óë¸Ã³ÌÊ½Íê³ÉÊ±µÄ°æ±¾ÏàÈÝ£¬µ«µ±ÖÐÈÔÈ»ÓÐÒ»Ð©¶Ô UPS
{\bfseries Ïàµ±ÖØÒª} µÄÖ§Ô®Ã»ÓÐÎÄ¼þËµÃ÷¡£

µ×ÏÂËù¼òÊöµÄ¿ØÖÆ»úÖÆÖ»ÄÜÈÃ {\ttfamily powerd} ËÍ¸ø {\ttfamily init} {\ttfamily powerfail} »ò
{\ttfamily powerok} ÕâÁ½¸öÑ¶Ï¢Ö®Ò»¶øÒÑ¡£{\ttfamily init} ½Óµ½ {\ttfamily powerfail} 
Ñ¶Ï¢Ê±Ö´ÐÐÒ»¸öÃüÁî£¬¶øµ±Ëü½Óµ½ {\ttfamily powerok} Ê±ÔòÖ´ÐÐÁíÒ»¸öÃüÁî¡£
Õâ½«µ¼ÖÁ {\ttfamily powerd} ÔÚ´¦ÀíµÍµçÁ¦Ñ¶ºÅ¼°ÆäËûÌØÊâ×´¿öÊ±²úÉúÂß¼­ÉÏµÄ¸´ÔÓÐÔ¡£

½ÏÐÂ°æ±¾µÄ {\ttfamily init} (ÏñÊÇ 2.58 °æ) ¾Í±È½Ï¾«Á¼ÁË¡£
Ëü¿ÉÒÔÔÚ½Óµ½Ñ¶ºÅÊ±Ñ¡Ôñ {\ttfamily Èý¸ö} script ÖÐÖ®Ò»À´Ö´ÐÐ¡£Èç´ËÒ»À´£¬ {\ttfamily init}
¿ÉÒÔÔÚ½Óµ½µçÔ´¶ÏµçÑ¶ºÅÊ±Ö´ÐÐ {\ttfamily powerfail} script £¬¿ÉÒÔÖ´ÐÐÒ»¸ö
{\ttfamily powerfailnow} script ×öÁ¢¼´µÄ¹Ø»ú £¬ÒÔ¼°Ò»¸ö {\ttfamily powerok} script
À´Í£Ö¹ÈÎºÎÕýÔÚ½øÐÐµÄ¹Ø»ú¶¯×÷¡£ÕâÑù±ÈÆðÒªÎÒÃÇ×ÔÐÐ´¦ÀíÕâÐ©»úÖÆÒª¼òµ¥¶àÁË¡£

¾¡¹ÜÕâ¡õ´ó²¿·ÖµÄÌÖÂÛÈÔ¼ÙÉèÊ¹ÓÃ¾ÉµÄ {\ttfamily init} Í¨Ñ¶·½Ê½£¬
ÎÒÒÑ¼ÓÈëÁËÁ½¸öÐÂµÄÕÂ½ÚÀ´ÃèÊöÐÂµÄÁ¬Ïß·½·¨¡£ÕâÁ½¸öÕÂ½ÚÊÇ \ref{ciro} {(Trust Energy Protector 400/650)} ¼° \ref{apc700} {(APC Smart-UPS 700)}¡£ÆäÖÐÇ°ÕßÌØ±ðÏêÏ¸¡£¶þÕß¶¼°üº¬ÁËÒ»¸ö {\ttfamily powerd.c} µµ£¬
Ëü¿ÉÒÔÔÚÊÕµ½µÍµçÁ¦Ñ¶ºÅÊ±ËÍÑ¶ºÅ¸ø {\ttfamily init} ÒÔ½øÐÐ½ô¼±¹Ø»ú£¬
¾ÍÏñÊÇ {\ttfamily /etc/inittab} µµÖÐÄÇ¼¸ÐÐËùÐ´µÄÒ»Ñù¡£ÆäâÅµÄ£¬
ÎÒËùÄÜ¸æËßÄúµÄ¾ÍÖ»ÓÐÇëÄú¿´¿´ {\ttfamily init} µÄÔ­Ê¼ÂëÁË¡£

¾ÍÎÒËùÖªµÄ£¬ÔÚÒÔÏÂËùÁÐµÄ UPS ÈíÌåÌ×¼þÖÐÓÐÐí¶àÒ²²ÉÓÃÁËÐÂÊ½µÄÁ¬Ïß·½Ê½¡£




\section{´ÏÃ÷µÄÓëµ¥µ÷µÄ UPS}

UPS ´óÖÁ·ÖÎªÁ½Àà£¬ÎÒ·Ö±ð½ÐËüÃÇ ``´ÏÃ÷µÄ (Smart)''Óë ``µ¥µ÷µÄ (Dumb)''¡£
¶þÕßÖ®¼äµÄ²îÒìÔÚì¶ÎÒÃÇÄÜ×Ô UPS »ñµÃ¶àÉÙµÄÑ¶Ï¢ÒÔ¼°ÎÒÃÇÄÜ¹»¶Ô UPS ÏÂ´ï¶àÉÙÃüÁî¡£



\begin{description}
\item[µ¥µ÷µÄ UPS] \mbox{}

\begin{itemize}
\item ½åÓÉÐòÁÐ¸· (serial port) ÓëµçÄÔÏàÁ¬¡£
\item Ê¹ÓÃ modem ¿ØÖÆÏßÓëµçÄÔÏàÍ¨Ñ¶¡£
\item ¿ÉÒÔÔÚµçÁ¦ÊÇ·ñÏûÊ§Ê±¸øµçÄÔËÍÑ¶ºÅ¡£
\item Ò²Ðí¿ÉÒÔÔÚ UPS µÄµçÁ¦ÊÇ·ñÆ«µÍÊ±Í¨ÖªµçÄÔ¡£
\item µçÄÔÍ¨³£¿ÉÒÔËÍÑ¶ºÅ¸ø UPS ÈÃËü½«×Ô¼º¹Ø±Õ¡£
\end{itemize}




\item[´ÏÃ÷µÄ UPS] \mbox{}

\begin{itemize}
\item ½åÓÉÐòÁÐ¸· (serial port) ÓëµçÄÔÏàÁ¬¡£
\item ÒÔÒ»°ãµÄ×ÊÁÏ´«ÊäÏß¾­ÐòÁÐ¸·ÓëµçÄÔ¹µÍ¨¡£
\item ¶à°ëÓÐÒ»×éÃüÁîÓïÑÔ¿ÉÒÔÈÃµçÄÔ×Ô UPS ÄÇµÃÖª¸÷Ê½¸÷ÑùµÄ×ÊÑ¶£¬
ÒÔÉè¶¨¸÷ÖÖÔË×÷²ÎÊý¸ø UPS£¬Í¬Ê±Ò²²Ù×÷ UPS (ÏñÊÇ½«Ëü¹Øµô)
\end{itemize}




\end{description}




Í¨³£´ÏÃ÷µÄ UPS ¶¼¿ÉÒÔÔÚµ¥µ÷µÄÄ£Ê½ÏÂ²Ù×÷¡£ÕâÊÇºÜÓÐÓÃµÄ£¬ÒòÎª¾ÍÎÒËùÖª£¬
×î³£¼ûµÄ´ÏÃ÷ UPS (ÏñÊÇ APC) ÖÆÔìÉÌÖ»Ô¸ÒâÍ¸Â¶ËûÃÇµÄ UPS 
Í¨Ñ¶Ð­¶¨¸øÄÇÐ©Ç©ÊðÁË¾ø²»¡õÂ¶»úÃÜÍ¬ÒâÊéµÄÈËÃÇ¡£

¾ÍÎÒËùÖª£¬Ö»ÓÐ BEST ¹«Ë¾ËùÖÆ×÷µÄ UPS ¿ÉÒÔºÜÈÝÒ×µØÔÚ Linux ÏÂÔË×÷¡£
³ý´ËÖ®Íâ£¬ BEST ¹«Ë¾»¹ÓÐÍêÕûµÄÎÄ¼þËµÃ÷ÁËËûÃÇµÄ UPS µÄ´ÏÃ÷Ä£Ê½ 
(ÒÔ¼°µ¥µ÷Ä£Ê½)¡£ BEST ¹«Ë¾Ò²Ìá¹©ÁË¿ÉÒÔÓëËûÃÇµÄ UPS ¹µÍ¨µÄ³ÌÊ½µÄÔ­Ê¼Âë¡£

ËùÓÐÁÐÔÚ \ref{software} {(ÈíÌå)} ÕÂ½ÚµÄÈíÌå½Ô¿ÉÔÚµ¥µ÷Ä£Ê½ÏÂÓë
UPS ¹µÍ¨¡£ÕâÐ©¶¼ÊÇÄúÕæÕýÐèÒªµÄ¡£ÓÐÐ©ÈíÌåÔòÐû³ÆËµ¿ÉÒÔÔÚ´ÏÃ÷Ä£Ê½ÏÂ²Ù×÷
ARC UPS £¬µ«ÎÒ²»ÖªµÀËûÃÇÊÇÈçºÎ»ñ×¼¶ø×öµ½µÄ¡£
Ò»¸öÍêÕûµÄ³ÌÊ½ÔË×÷»áÌø³öÒ»¸öÊÓ´°£¬¡õÍ·°üº¬ÁËÓÐÈ¤µÄ¶ÈÁ¿±í£¬
´ú±íÖø¸÷Ê½¸÷ÑùµÄ UPS Í³¼Æ×ÊÁÏ£¬ÏñÊÇ¸ºÔØ³Ì¶È¡¢ÄÚ²¿ÎÂ¶È¡¢¶Ïµç¼ÇÂ¼¡¢ÊäÈëµçÑ¹¡¢
¼°Êä³öµçÑ¹ ...... µÈµÈ¡£¿´ÆðÀ´ËÆºõ {\ttfamily smupsd-0.7-1.i386.rpm} ³ÌÊ½
(¼û \ref{software} {(ÈíÌå)}Ò»½Ú) ¿ÉÒÔ×öµ½ÕâÐ©¡£
¶Ôì¶ÆäËûµÄÈíÌåÎÒÔò²»¸ÒÈ·¶¨¡£

ÒÔÏÂµÄÄÚÈÝÎÒ½«¾¡Á¿¡õÏÞì¶ÈçºÎµ÷ÕûÄúµÄÏµÍ³Ê¹ÆäÄÜÓëµ¥µ÷Ä£Ê½ÏÂµÄ UPS Ò»Æð¹¤×÷¡£
¶ø¶Ô´ÏÃ÷Ä£Ê½µÄ UPS ¶øÑÔ£¬»ù±¾Ïë·¨ÊÇÒ»ÑùµÄ£¬µ«ÐèÒªÊ²÷áÑùµÄ {\ttfamily powerd} 
²ÎÓë¹¤×÷ÒÔ¼°ÄúÐèÒªÊ²÷áÑùµÄÑ¶ºÅÀÂÏßÊÇËæÖø UPS ¶øÓÐ²»Í¬µÄ¡£






\section{ÈíÌå\label{software}}

»ù±¾ÉÏ£¬ÄúËùÐèµÄ¾ÍÊÇÒ»¸ö¿ÉÒÔ¹¤×÷ {\ttfamily powerd} ³ÌÊ½µµ£¬Í¨³£Äú¿ÉÒÔÔÚ
{\ttfamily /sbin/powerd} ÏÂÕÒµ½Ëü¡£ËüÍ¨³£ÊÇÊôì¶ {\ttfamily SysVinit} ÏµÍ³µÄÒ»²¿·Ö¡£
¾ÍÎÒËùÖª£¬ËùÓÐ½üÆÚ°æ±¾µÄ Linux ÏµÍ³¶¼°üº¬ÁËÒ»¸ö½ÏÐÂ°æµÄ {\ttfamily SysVinit} ¡£
µ«ÔÚ·Ç³£¾ÉµÄ°æ±¾Ôò²»°üº¬ {\ttfamily powerd}¡£

Î¨Ò»µÄÎÊÌâÊÇÄúµÄÑ¶ºÅÀÂÏß¿ÉÄÜ²»ÄÜÓëÄúµÄ {\ttfamily powerd} Éè¶¨ÏàÅäºÏ£¬
ÔÚÕâÇé¿öÏÂÄú±ØÐëÖØÐÂ×öÒ»ÌõÑ¶ºÅÀÂÏß£¬»òÕßÊÇÕÒÀ´Ò»·Ý {\ttfamily powerd.c} 
µµ²¢ÐÞ¸ÄËüÊ¹µÃËüÄÜÅäºÏÄúµÄÑ¶ºÅÀÂÏß¹¤×÷¡£»òÕßÊÇ£¬
Äú¿ÉÒÔÊ¹ÓÃÒÔÏÂËùÁÐµÄÈíÌå£¬´ó²¿·ÖµÄÈíÌåÔÊÐíÄú×öÊÊµ±µÄÉè¶¨ÒÔÅäºÏÄúµÄÑ¶ºÅÀÂÏß¡£

¾ÍÏñ¸Õ¸ÕËùÌáµ½µÄ£¬³ýÁËÊ¹ÓÃ {\ttfamily SysVinit} µÄ {\ttfamily powerd} 
Ö®ÍâÄúÒ²¿ÉÒÔÄÃÏÖÓÐµÄÈÎºÎÒ»ÖÖ UPS ÈíÌåÀ´ÓÃ¡£Ä¿Ç°ÓÐÐí¶àÈíÌå¿ÉÒÔ°ïÖúÄú½¨Á¢µçÄÔÓë
UPS Ö®¼äµÄÁ¬Ïß¡£ÔÚÎÒµÚÒ»´ÎÐ´ÕâÆª HOWTO Ê±¶¼»¹Ã»ÓÐÕâÐ©ÈíÌå£¬
¶øÕâÒ²ÊÇÎªÊ²÷áÎÒÒªÐ´ÕâÆª HOWTO ¡£ÊÂÊµÉÏ£¬ÄúÒ²¿ÉÒÔ´ÓÖÐÑ¡Ò»¸öÈíÌåÀ´ÓÃ£¬
¶øÍêÈ«ºöÂÔÕâÆª HOWTO µÄÄÚÈÝ¡£

ÔÚ 1997 Äê 3 ÔÂ 15 ÈÕ×óÓÒ£¬ \nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups}{Sunsite µÄ UPS Ä¿Â¼} 
ÏÂ¿ÉÒÔÕÒµ½Ò»´ó¶ÑµÄÈíÌå¿ÉÓÃ¡£¶øÔÚÆäËûµÄÍøÕ¾ËÆºõÒ²ÓÐ UPS ¿ØÖÆÈíÌå¿ÉÒÔÕÒµ½¡£
ÒÔÏÂÊÇÎÒÄ¿Ç°ËùÕÒµ½µÄ (³ýÁËÆäÖÐÁ½¸öÒÔÍâ£¬ÆäËû¶¼ÊÇÔÚ sunsite ÕÒµ½µÄ):

\begin{description}
\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/Enhanced_APC_BackUPS.tar.gz}{Enhanced\_APC\_BackUPS.tar.gz}] \mbox{}

ÕâÊÇÒ»¸ö¿ÉÒÔ¿ØÖÆ APC ´ÏÃ÷Ä£Ê½µÄ UPS ¡£¿´ÆðÀ´»ù±¾ÉÏÊÇÒÀ¾Ý BUPS Howto
(°üº¬ÁËÕâÒ»Æª) £¬µ«Ò²ºÃÏñÓÐÒ»Ð©µÍµçÁ¦¾¯¸æµÄÖ§Ô®¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/Enhanced_APC_UPSD-v1.4.tar.gz}{Enhanced\_APC\_UPSD-v1.4.tar.gz}\label{Enhanced}] \mbox{}

ÔÚ {\ttfamily .lsm} µµÖÐÌáµ½Ëü´ÓÇ°¾ÍÊÇÉÏÒ»¸öËùÌáµ½µÄÈíÌå£¬
µ«ÊÂÊµÉÏËüÕýÊÇ½«ÉÏÒ»¸öÈíÌåµÄ {\ttfamily .tar.gz} µµ°ü×°ÔÚËüµÄ {\ttfamily tar.gz} 
µµÖ®ÄÚ¡£ÄÇÆªÎÄ¼þËµÃ÷ÓÐÎÊÌâ£¬¿´ÆðÀ´ËüËÆºõÍ¬Ê±Ö§Ô® APC UPS 
µÄ´ÏÃ÷Óëµ¥µ÷Ä£Ê½£¬µ«ÎÒ²»¸ÒÈ·¶¨¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/apcd-0.5.tar.gz}{apcd-0.5.tar.gz}\label{apcd}] \mbox{}

ÕâÊÇÁíÒ»¸ö¿ÉÒÔ¿ØÖÆ APC UPS ì¶´ÏÃ÷Ä£Ê½ÏÂÔË×÷µÄÈíÌå¡£
¿´ÆðÀ´ËÆºõ¿ÉÒÔÖ§Ô®Ö÷/´ÓÄ£Ê½
(Ò²¾ÍÊÇËµ£¬µ±Í£µçÊ±¿ÉÒÔÓÉÒ»Ì¨»úÆ÷ËÍÑ¶ºÅ¸øÁíÒ»Ì¨»úÆ÷½ÐËü¹Ø»ú) ¡£
¿´ÆðÀ´ËÆºõÊÇÊ¹ÓÃÁË UPS µÄ´ÏÃ÷Ä£Ê½£¬²»ÏñÊÇ¾­ÓÉ modem µÄÑ¶ºÅÏßÀ´¿ØÖÆ¡£



\item[\nameurl{ftp://cms180.cmsnet.com/pub/smupsd/}{smupsd directory}\label{smupsd}] \mbox{}

ÓÖÊÇÁíÒ»¸ö¿ØÖÆ APC UPS µÄÈíÌå¡£¿´ÆðÀ´¿ÉÒÔÔÚ·Ç³£´ÏÃ÷ (tm) Ä£Ê½ÏÂ²Ù×÷
UPS ¡£¾ÙÀýÀ´Ëµ£¬Ëü°üº¬ÁËÒ»¸ö Java Í¼ÐÎ½éÃæµÄ UPS ¼à¿Ø¹¤¾ß³ÌÊ½¡£
¸ÃÄ¿Â¼ÏÂ°üº¬ÁËÒÑ±àÒëºÃµÄ RPM ÐÎÊ½µÄÈíÌå (\onlynameurl{ftp://cms180.cmsnet.com/pub/smupsd/smupsd-0.7-1.i386.rpm}) £¬
Ò»¸öÔ­Ê¼Âë RPM ¸ñÊ½µµ (\onlynameurl{ftp://cms180.cmsnet.com/pub/smupsd/smupsd-0.7-1.src.rpm}) £¬
ÒÔ¼°Ò»¸ö¡õÎÒµµ°¸ (\onlynameurl{ftp://cms180.cmsnet.com/pub/smupsd/smupsd-0.7-1.README}) ¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/genpower-1.0.1.tgz}{genpower-1.0.1.tgz}\label{genpower}] \mbox{}

Ò»¸öÒ»°ã»¯µÄ UPS ¿ØÖÆÈíÌå¡£Ëü°üº¬ÁËºÜ¶àÖÖ UPS µÄÉè¶¨ --- Á½ÖÖ TrippLite
µÄÉè¶¨£¬ÒÔ¼°ÈýÖÖ APC µÄÉè¶¨¡£Í¬Ê±Ò²°üº¬ÁËºÜºÃµÄËµÃ÷ÎÄ¼þ¡£Îï³¬ËùÖµ¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/powerd-2.0.tar.gz}{powerd-2.0.tar.gz}\label{ powerd2}] \mbox{}

Ò»¸ö {\ttfamily SysVinit} µÄ {\ttfamily powerd} ³ÌÊ½µÄÌæ´úÆ·¡£
ÓëËüµÄËµÃ÷ÎÄ¼þËùÌáµ½µÄÏà·´£¬ËüËÆºõÃ»ÓÐÕûºÏµ½ {\ttfamily SysVinit} 2.62 
°æÖÐ¡£ËüµÄÓÅµãÔÚì¶Ëü¿ÉÒÔ×öÎªÔÚÆäËû»úÆ÷ÉÏÖ´ÐÐµÄ {\ttfamily powerd} µÄËÅ·þ¶Ë
(¼ÙÈçÄúµÄ»úÆ÷ÓÐÁ¬ÉÏÍøÂ·ÇÒÖ»ÓÐÒ»¸ö UPS µÄ»°) £¬¶øÇÒËü¿ÉÒÔÓÃÉè¶¨µµÀ´½øÐÐÉè¶¨
---- ¹ÊÆäÔ­Ê¼Âë²»ÐèÐÞ¸Ä¼°ÖØÐÂ±àÒë¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/upsd-1.0.tgz}{upsd-1.0.tgz}\label{upsd}] \mbox{}

ÁíÒ»¸ö {\ttfamily powerd} µÄÌæ´úÆ·¡£¿´ÆðÀ´ËÆºõÓë powerd-2.0.tar.gz 
ÓÐÐí¶àÏàËÆµÄÌØÉ«¡£



\item[\nameurl{http://www.bestpower.com/section/software/checkups.tar}{checkups.tar}\label{checkups }] \mbox{}

Õâ¸öÈíÌåÊÇÓÃÀ´¿ØÖÆ Best UPS µÄ¡£ËüÊÇÖ±½ÓÀ´×Ô Best ¹«Ë¾µÄÍøÒ³µÄ¡£
Ëü°üº¬ÁË¶àÖÖ {\ttfamily unix} µÄ¿ÉÖ´ÐÐµµ£¬µ«¸üÖØÒªµÄÊÇ£¬Ëü»¹°üº¬ÁËÔ­Ê¼Âë£¬
¹ÊÄú¿ÉÒÔÔÚ Linux ÏÂ²âÊÔËü£¬¶øÇÒ¼ÙÈçËüÎÞ·¨¹¤×÷£¬ÄúÒ²¿ÉÒÔÊÔÖøÐÞ¸ÄËü¡£
´ËÔ­Ê¼ÂëÍ¬Ê±°üº¬ÁËÔÚµ¥µ÷Ä£Ê½ÏÂ¿ØÖÆ UPS µÄ "»ù±¾¼ì²â" Ö¸Áî£¬
ÒÔ¼°Ò»Ð©¸ü¾«ÇÉµÄ "ÏÈ½ø¼ì²â" Ö¸Áî --- µ± UPS »Ø±¨ËµËüÖ»Ê£ X 
·ÖÖÓµÄµçÁ¦Ê±¼´·¢³ö¹Ø»úµÄÑ¶ºÅ£¬¶ø²»ÊÇµÈµ½ X ·ÖÖÓááµçÁ¦¶¼ÓÃ¹âÁË²Å¿ªÊ¼¹Ø»ú¡£
´ËÏÈ½ø¼ì²â³ÌÊ½Ò²»áÔÚ UPS ·¢³öÏñÊÇÖÜÎ§»·¾³ÎÂ¶È¹ý¸ß¡¢½Ó½üµÍµçÁ¦¡¢
µÍ½»Á÷µçÊä³ö¡¢»òÕßÊÇÊ¹ÓÃÕß²âÊÔµÈ¾¯¸æÊ±¹Ø±Õ»úÆ÷¡£



\item[\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/bestups-0.9.tar.gz}{bestups-0.9.tar.gz}\label{bestups}] \mbox{}

¿ÉÄÜÔÚÄú¶Áµ½ÕâÆªÎÄÕÂÊ±£¬´ËÔÚ sunsite ¿ÉÒÔÕÒµÃµ½µÄÈíÌåÒÑ·¢Õ¹µÃºÜºÃÁË¡£
ËüÊÇÒ»¶Ô¿ÉÒÔÏà»¥Í¨Ñ¶µÄÄ£×é£¬ÓÃÒÔ¿ØÖÆ Best Ferrups UPS¡£Ëü¿ÉÒÔÔÚ´ÏÃ÷Ä£Ê½ÏÂ
¿ØÖÆ UPS ¡£Ëü¿ÉÒÔÓë powerd-2.0 ºÏ×÷²Ù¿Ø --- ÕâÒ»µãÔÚµ±ÄúÓÐÒ»¸ö´óÐÍµÄ
Best Ferrups UPS Ö§Ô®Á¬½ÓÔÚÍøÂ·ÉÏ»úÆ÷µÄµçÁ¦Ê±¸ñÍâÓÐÓÃ¡£



\end{description}




Çë×¢ÒâÎÒÖ»ÊÇ¿ìËÙµØä¯ÀÀ¹ýÕâÐ©ÈíÌå¡£ÎÒ²¢Ã»ÓÐÓÃËüÃÇ£¬³ýÁËÄÇ¸öÎÒÃÇ²Å¿ªÊ¼Ê¹ÓÃµÄ
\nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/bestups-0.9.tar.gz}{bestups-0.9.tar.gz}
ÒÔ¼° \nameurl{http://sunsite.unc.edu:/pub/Linux/system/ups/powerd-2.0.tar.gz}{powerd-2.0.tar.gz} £¬
ÆäÖÐ ``²Å¿ªÊ¼'' ÒâË¼ÊÇËµÎÒÃÇ²ÅÔÚÉÏ¸öÐÇÆÚËÄ¿ªÊ¹×ö²âÊÔ¡£




\section{×Ô¼º¶¯ÊÖÖ¸ÄÏ}

Õâ¡õµÄÌÖÂÛÊÇÕë¶Ôµ¥µ÷Ä£Ê½µÄ UPS ¿ØÖÆ¶øÐ´¾ÍµÄ¡£È»¶ø£¬
´ó²¿·ÖµÄ¹ý³Ì¶Ôµ¥µ÷µÄ UPS Óë´ÏÃ÷µÄ UPS ¼¸ºõÊÇÒ»ÑùµÄ¡£×î´óµÄ²»Í¬ÔÚì¶ UPS
¼à¿Ø³ÌÊ½ (»ù±¾ÉÏÊÇ {\ttfamily powerd}) ÈçºÎÓë UPS ¹µÍ¨¡£

ÔÚ¿ªÊ¼Ö®Ç°£¬ÎÒ½¨ÒéÒÔÏÂµÄ¹¤×÷Á÷³Ì:
\begin{itemize}
\item ÂÔ¶ÁÕâÆªÎÄ¼þ¡£
\item ÏÂÔØ²¢Éó²éËùÓÐ¿´ÆðÀ´ÌØ±ðÊÊºÏÄúµÄ UPS µÄÈíÌå¡£
\item ÏÂÔØ²¢Éó²éËùÓÐ¸üÒ»°ã»¯µÄÈíÌå¡£Çë×¢ÒâÓÐÐ©½ÏÒ»°ã»¯µÄÈíÌåÊÂÊµÉÏ¸üÎªÇ¿´ó¡¢
ÓÐ¸üºÃµÄËµÃ÷ÎÄ¼þ¡¢ÇÒ±ÈÆðÄÇÐ©½ÏÌØÊâµÄÈíÌå¸üÈÝÒ×Ê¹ÓÃ¡£
\item Èç¹ûÄúÒÀÈ»ÎÞ·¨ÈÃ UPS ¹¤×÷£¬»òÊÇÄúµÄ·½ÏòÒÀ¾É²»Çå³þ£¬
ÇëÄú×ÐÏ¸ÔÄ¶Á±¾ÎÄ£¬²¢ÊÔÊÔ×ö hack µÄ¹¤×÷ ....
\end{itemize}







\subsection{ÄúËùÐèµÄ¹¤×÷ (×Ü½á)}

\begin{itemize}
\item ½«ÄúµÄµçÄÔ½ÓÉÏ UPS ¡£
\item ÓÃÌØÊâµÄÑ¶ºÅÀÂÏß½«ÄúµÄµçÄÔµÄµÄ´®ÁÐ¸·Óë UPS Á¬½ÓÔÚÒ»Æð¡£
\item ÔÚÄúµÄµçÄÔÉÏÅÜ {\ttfamily powerd} (»òÆäËûÀàËÆµÄÈíÌå) ¡£
\item Éè¶¨ÄúµÄ {\ttfamily init} ³ÌÊ½Ê¹ËüÄÜÔÚ powerfail ¼° powerok 
ÊÂ¼þ·¢ÉúÊ±×öÊÊµ±µÄ´¦Àí (ÀýÈç·Ö±ðÆô¶¯ {\ttfamily shutdown} ³ÌÐò¼°Í£Ö¹ÕýÔÚÖ´ÐÐµÄ
{\ttfamily shutdown} ³ÌÐò)¡£
\end{itemize}





\subsection{ÕâÓ¦¸ÃÊÇ×öÊ²÷á¹¤×÷µÄ?}



\begin{description}
\item[UPS µÄ¹¤×÷] \mbox{}

µ±µçÁ¦ÏûÊ§Ê±£¬ UPS ³ÖÐø¹©Ó¦µçÄÔËùÐèµÄµçÁ¦£¬
²¢ÒÔËÍ³öÖØÖÃÑ¶ºÅ»òÊÇÔÚËüµÄ¿ØÖÆ¸·ÉÏ´ò¿ªÁ¬½ÓÑ¶ºÅÒÔÍ¨ÖªµçÄÔµçÁ¦ÏûÊ§ÁË¡£



\item[Ñ¶ºÅÀÂÏßµÄ¹¤×÷] \mbox{}

Ñ¶ºÅÀÂÏßÊÇÉè¼ÆÎªµ± UPS ËÍ³öÖØÖÃÑ¶ºÅÊ±£¬»áÊ¹µÃÌØÊâµÄÐòÁÐ¸·¿ØÖÆ½Ó½Å
(»ù±¾ÉÏÊÇ {\ttfamily DCD}) ³öÏÖ¸ßµçÎ»¡£



\item[Powerd µÄ¹¤×÷] \mbox{}

{\ttfamily powerd} ³ÌÊ½¸ºÔð¼àÊÓÐòÁÐ¸·¡£Ëü±£³ÖÖø UPS ËùÐè¶øÉý¸ß / 
½µµÍÐòÁÐ¸·¿ØÖÆ½Ó½ÅµÄ¸ß / µÍµçÎ» (»ù±¾ÉÏ£¬ {\ttfamily DTR}
½Ó½Å±ØÐë±£³ÖÔÚ¸ßµçÎ»ÇÒ¹Ø±Õ UPS µÄ½Ó½Å±ØÐë±£³ÖÔÚµÍµçÎ») ¡£µ± {\ttfamily powerd}
·¢¾õ¿ØÖÆ½Ó½Å±ä³É¸ßµçÎ»£¬Ëü»áÔÚ {\ttfamily /etc/powerfail} µµÖÐÐ´Èë
{\ttfamily FAIL} Õâ¸ö×Ö²¢ËÍ {\ttfamily SIGPWR} Ñ¶ºÅ¸ø {\ttfamily init} ÐÐ³Ì¡£
µ±¿ØÖÆ½Ó½ÅÔÙ´Î±ä»ØµÍµçÎ»Ê±£¬Ëü»áÔÚ {\ttfamily /etc/powerfail} 
µµÖÐÐ´Èë {\ttfamily OK} Õâ¸ö×Ö²¢ËÍ {\ttfamily SIGPWR} Ñ¶ºÅ¸ø {\ttfamily init} ¡£



\item[Init µÄ¹¤×÷ (³ýÉÏÊöÖ®ÍâËü¸ºÔðËùÓÐµÄ¹¤×÷)] \mbox{}

µ±Ëü½Óµ½ÁË {\ttfamily SIGPWR} Ñ¶ºÅ£¬Ëü»á¼ì²é {\ttfamily /etc/powerfail} µµ¡£
Èç¹û¡õÍ·ÊÇ {\ttfamily FAIL} Õâ¸ö×ÖÑÛËü»áÖ´ÐÐ {\ttfamily /etc/inittab}
µµÖÐ {\ttfamily powerfail} ÄÇÒ»ÐÐµÄÖ¸Áî¡£Èç¹û¡õÍ·ÊÇ {\ttfamily OK} 
Õâ¸ö×ÖËüÔòÖ´ÐÐ {\ttfamily inittab} µµÖÐ {\ttfamily powerokwait} ÄÇÒ»ÐÐµÄÖ¸Áî¡£



\end{description}





\subsection{ÈçºÎÉè¶¨ºÃËùÓÐµÄ¹¤×÷}



ÒÔÏÂÎÒÃÇ¼ÙÉèÄúÓÐÒ»Ìõ¿ÉÒÔºÍ {\ttfamily powerd} Õý³£¹¤×÷µÄÑ¶ºÅÀÂÏß¡£
Èç¹ûÄú²»È·¶¨ÄúµÄÑ¶ºÅÀÂÏßÊÇ·ñ¿ÉÒÔ¹¤×÷ (»òËüÈçºÎ¹¤×÷)£¬Çë²Î¿¼
\ref{hacking} {(Ñ¶ºÅÀÂÏß·´Ïò·ÖÎö¼°ÐÞ¸Ä power.c)}
Ò»½Ú£¬ÄÇ¶ùÓÐ¹Øì¶ÉÙ¼ûµÄÑ¶ºÅÀÂÏß´¦Àí¼°ÖØÐÂÉè¶¨ {\ttfamily powerd.c} µÄ×ÊÑ¶¡£
\ref{serial-port} {(ÐòÁÐ¸·½Ó½ÅµÄÖ¸¶¨)} ¼°
\ref{ioctl} {(ÓÐ¹Ø¶ÁÐ´ RS232)} ÕâÁ½½ÚÒ²½«¶ÔÄúÓÐ°ïÖú¡£

Èç¹ûÄúÐèÒªÖÆ×÷Ò»ÌõÑ¶ºÅÀÂÏß£¬Çë¼û \ref{make-cable} {(ÈçºÎÖÆ×÷Ñ¶ºÅÀÂÏß)} µÄÏêÏ¸ËµÃ÷£¬ÒÔ¼° \ref{ups-specific} {(UPS ×ÊÁÏ½ÚÑ¡)} Ò»½ÚÖÐÓÐ¹ØÄúµÄ UPS µÄÐ¡½Ú¡£
ááÕß¿ÉÄÜÒ²°üº¬ÁËÖÆÔìÉÌËùÌá¹©µÄÑ¶ºÅÀÂÏßµÄÏà¹Ø×ÊÑ¶¡£
»òÐíÄúÓ¦ÖÁÉÙ½« \ref{ups-specific} {(UPS ×ÊÁÏ½ÚÑ¡)}
ÖÐËùÓÐµÄÐ¡½Úä¯ÀÀ¹ýÒ»±é£¬ÒòÎªÃ¿Ò»Ð¡½Ú¶¼»áÓÐÒ»Ð©¶îÍâµÄÒ»°ãÐÔ×ÊÁÏÄÜ¶ÔÄúÓÐ°ïÖú¡£

\begin{itemize}
\item ÐÞ¸Ä {\ttfamily /etc/inittab} µµ¡£Ð´ÈëÏñÒÔÏÂµÄÄÚÈÝ:

\begin{verbatim}
# What to do when power fails (Halt system & drain battery :):
pf::powerfail:/etc/powerfailscript +5

# If power is back before shutdown, cancel the running shutdown.
pg:0123456:powerokwait:/etc/powerokscript
   
\end{verbatim}

\item Ð´ {\ttfamily /etc/powerfailscript} ¼° {\ttfamily /etc/powerokscript}
ÕâÁ½¸ö script µµ·Ö±ðÔÚÎå·ÖÖÓ (»òÆäËûÄúÏ²»¶µÄÊ±¼ä) 
Ö®ÄÚ½øÐÐ¹Ø»ú¼°Í£Ö¹ÈÎºÎ´æÔÚµÄ {\ttfamily shutdown} ³ÌÐò¡£
ÒÀÄúËùÓÃµÄ {\ttfamily shutdown} ³ÌÊ½°æ±¾µÄ²»Í¬£¬
Ëü¿ÉÄÜ»áÏàµ±µ¥¼òÒÔÖÁì¶Äú¸ù±¾²»ÐèÊ¹ÓÃ script µµ£¬»òÕßÊÇÒ»ÐÐ {\ttfamily bash}
µÄ script µµÏñÊÇÒÔÏÂÕâÒ»ÐÐ:

\begin{verbatim}
    kill `ps -aux | grep "shutdown" | grep -v grep | awk '{print $2}'`
\end{verbatim}

      
(ÎªÁË±ÜÃâÄúÅª´í£¬ÉÏÒ»ÐÐÖÐµÚÒ»¸öµ¥ÒýºÅÊÇ·´Ïòµ¥ÒýºÅ£¬µÚ¶þ¼°µÚÈý¸öÊÇµ¥ÒýºÅ£¬
¶ø×îááÒ»¸öÔòÎª·´Ïòµ¥ÒýºÅ¡£)
\item ÓÃÒÔÏÂµÄÃüÁî¸æËß {\ttfamily init} ÖØÐÂ¶ÁÈ¡ {\ttfamily inittab} µµÖÐµÄÉè¶¨:


\begin{verbatim}
    telinit q
   
\end{verbatim}

\item ±à¡õ rc.local µµÔÚ¿ª»úÊ±Ö´ÐÐ {\ttfamily powerd} ¡£ÆäÓï·¨ÈçÏÂ:

\begin{verbatim}
    powerd <line>
    
\end{verbatim}


ÆäÖÐ£¬ÇëÄú×ÔÐÐ½« {\ttfamily $<$line$>$} Õâ¸ö×ÖÌæ»»³É modem 
ËùÁ¬½ÓµÄÐòÁÐ¸·Ãû£¬ÏñÊÇ {\ttfamily /dev/cua1}¡£
\item ½«µçÄÔµÄÐòÁÐ¸·Óë UPS µÄÑ¶ºÅÀÂÏßÏàÁ¬¡£ÇëÏÈ²»Òª½«µçÄÔµÄµçÔ´Ö±½Ó½Óµ½ 
UPS ÉÏ¡£
    
\item ½«Ò»¸ö¹âÔ´ (ÈçµÆÅÝ) ½Óµ½ UPS ÉÏ¡£
\item Ö´ÐÐ {\ttfamily powerd}¡£
\item ÒÀÕÕÒÔÏÂµÄ²½Öè½øÐÐ²âÊÔ:
\begin{itemize}
\item °Îµô UPS µÄ²åÍ·¡£
\begin{itemize}
\item ¼ì²é¸ÃµÆÅÝÊÇ·ñÈÔÈ»ÁÁÖø¡£
\item ¼ì²é {\ttfamily /etc/powerfailscript} ÊÇ·ñÒÑ¿ªÊ¼Ö´ÐÐ¡£
\item ¼ì²é {\ttfamily shutdown} ÊÇ·ñÕýÔÚÖ´ÐÐ¡£
\end{itemize}
\item ½Ó»Ø UPS µÄ²åÍ·¡£
\begin{itemize}
\item ¼ì²é¸ÃµÆÅÝÊÇ·ñÈÔÈ»ÁÁÖø¡£
\item ¼ì²é {\ttfamily /etc/powerokscript} ÊÇ·ñÒÑ¿ªÊ¼Ö´ÐÐ¡£
\item ¼ì²é {\ttfamily /etc/powerfailscript} ÊÇ·ñÒÑÍ£Ö¹Ö´ÐÐ¡£
\item ¼ì²é {\ttfamily shutdown} ÊÇ·ñÒÑÍ£Ö¹Ö´ÐÐ¡£
\end{itemize}
\item ÔÙ´Î°Îµô UPS µÄ²åÍ·¡£·ÅÖø²»È¥¹ÜËü²¢È·¶¨µçÄÔÔÚÒ»¶ÎÊ±¼äáá
¿ÉÒÔÕý³£¹Ø»ú¡£
\item {\bfseries Î£ÏÕ²½Öè¡£} ÔÚËùÓÐµÄ²½Öè¿´ÆðÀ´¶¼Õý³£Ö®áá£¬
½«µçÄÔµçÔ´¹Ø±Õ²¢½«µçÄÔµÄµçÔ´½Óµ½ UPS ÉÏ¡£ÇëÖ´ÐÐÒ»¸ö script
´óÔ¼Ã¿ÃëÖÓ×öÒ»´Î sync Ó²µú×ÊÁÏ»Ø´æµÄ¶¯×÷£¬Í¬Ê±Ò²ÅÜÁíÒ»¸ö script
³ÖÐøÒÔ find Ö¸ÁîËÑÑ°Õû¿ÅÓ²µú¡£ÆäÖÐµÚÒ»¸ö script 
ÊÇÎªÁËÈ·±£°²È«£¬¶øµÚ¶þ¸öÔòÊÇÖú³¤µçÁ¦µÄÏûºÄ¡£ÏÖÔÚ£¬½« UPS
µÄ²åÍ·°Î³ö£¬ÔÙ´Î¼ì²é {\ttfamily shutdown} ÊÇ·ñÒÑÔÚÔË×÷£¬²¢µÈ´ýÒ»¶ÎÊ±¼ä¡£
È·¶¨µçÄÔÔÚ UPS µÄµçÁ¦ÓÃÍêÇ°ÍêÈ«µØ¹Ø»ú¡£´ËÒ»²½ÖèÊÇºÜÎ£ÏÕµÄ£¬
ÒòÎªÈç¹û UPS µÄµçÁ¦ÔÚµçÄÔÍê³É¹Ø»úÖ®Ç°ÏÈÓÃÍêÁË£¬
ÄúµÄµµ°¸ÏµÍ³½«»áÊÜËð£¬ÇÒÄú½«¿ÉÄÜ¶ªÊ§Ò»Ð©µµ°¸¡£
Äú¿ÉÄÜÔÚ½øÐÐÕâÏî²âÊÔÖ®Ç°»áÏëÒª±¸·ÝÄúËùÓÐµÄµµ°¸£¬
²¢½«¿ªÊ¼¹Ø»úµÄÊ±¼äÉè¶ÌÒ»µãÒÔ¿ªÊ¼ÕâÏî²âÊÔ¡£
\end{itemize}
\end{itemize}


¹§Ï²Äú! ÄúµÄ Linux ÏµÍ³ÏÖÔÚÒÑÔÚ UPS µÄ±£»¤ÏÂ£¬
ÇÒËü½«»áÔÚµçÁ¦ºÄ¾¡Ö®Ç°°²È«µØ¹Ø»úÁË¡£






\subsection{½øÒ»²½µÄ¸ÄÉÆ}



\begin{itemize}
\item ÐÞ¸Ä {\ttfamily powerd.c} Ê¹ËüÔÚ¼àÊÓ UPS µÄÑ¶ºÅÏßÊ±ÄÜµÃÖªµç³ØµçÁ¦ÒÑÈõ¡£
µ±µçÁ¦Î¢ÈõÊ±£¬ÂíÉÏ½øÐÐ½ô¼±¹Ø»ú³ÌÐò¡£
\item ÐÞ¸Ä¹Ø»ú³ÌÐòÊ¹ËüÔÚ {\ttfamily powerfail} Çé¿öÏÂ¹Ø»úÊ±£¬
ÄÜ¹»ÔÚÍê³ÉËùÓÐ¹¤×÷Ö®áá½« UPS ¹Øµô¡£
\end{itemize}





\section{Ó²ÌåµÄ×¢ÒâÊÂÏî}




\subsection{ÈçºÎÖÆ×÷Ñ¶ºÅÀÂÏß\label{make-cable}}

±¾½ÚµÄÄÚÈÝÖ»ÊÇÐ©ÎÒÔÚÍøÂ·ÉÏ¿´µ½µÄ×ÊÑ¶¡£ÎÒ²¢Ã»ÓÐÇ××ÔÊÔ¹ý£¬
ËùÒÔÎÒÎÞ·¨ÒÀÎÒµÄ¾­ÑéÐ´ÏÂÀ´¡£Èç¹ûÓÐÈËÓÐ¾­Ñé£¬Âé·³ÄúÎªÎÒÐ´ÕâÒ»½Ú :)¡£
Í¬Ê±Ò²ÇëÄú²Î¿¼ \ref{gps1000} {(ACCODATA µÄ GPS1000)} ÖÐÓÐ¹Ø 
GPS1000 µÄ×ÊÁÏ£¬²»±ØËµ£¬\ref{ups-specific} {(UPS ×ÊÁÏ½ÚÑ¡)}
ÕâÒ»½ÚÖÐËùÓÐÌØÊâ UPS µÄ×ÊÁÏÒ²ÊÇÖµµÃ²Î¿¼µÄ¡£

\begin{verbatim}
   >From miquels@caution.cistron.nl.mugnet.org Wed Jul 21 14:26:33 1993
   Newsgroups: comp.os.linux
   Subject: Re: UPS interface for Linux?
   From: miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg)
   Date: Sat, 17 Jul 93 18:03:37
   Distribution: world
   Organization: Cistron Electronics.

   In article <1993Jul15.184450.5193@excaliber.uucp>
   joel@rac1.wam.umd.edu (Joel M. Hoffman) writes:
   > ÎÒÕý´òËãÒª¹ºÂò UPS (²»¶ÏµçÏµÍ³)£¬ÎÒ×¢Òâµ½ÓÐÐ©¾ßÓÐ LAN µÄ½éÃæ£¬
   > ¿ÉÒÔÔÚÍ£µçÊ±Ïò LAN ËÍÑ¶ºÅ¡£
   >
   > ¶ø Linux ÓÐÃ»ÓÐÕâÑùµÄ½éÃæÄØ?
   >
   > Ð»Ð»ÄúµÄ»Ø´ð¡£
   >
   >-Joel
   >(joel@wam.umd.edu)
   >

   µ±ÎÒÔÚÐÞ¸ÄÉÏÒ»°æµÄ SysVinit Ê± (ÏÖÔÚµÄ°æ±¾ÊÇ 2.4)£¬
   ÄÇÊ±ÎÒµÄµçÄÔÓÐÒ»¸ö UPS £¬ËùÒÔÎÒ¼ÓÈëÁË¶ÔËüµÄÖ§Ô®¡£
   ÄúÒ²ÐíÒÑÔÚ×î½üµÄÒ»¸ö <signal.h> ±êÍ·µµÖÐ¿´µ½ÁË #define SIGPWR 30
   ÕâÒ»ÐÐ :-)¡£×ÜÖ®£¬ÎÒ²¢Ã»ÓÐÄÇ¸öÌØÊâµÄ½éÃæ£¬µ«´ó¶àÊýµÄ UPS
   ÊÇ¿¿²úÉú»òÖÐ¶ÏÒ»¸öµçÔ´ÖÐ¶ÏÑ¶ºÅÔÚÔË×÷µÄ¡£
   ÎÒÏëµ½Ò»¸ö¼òµ¥µÄ·½Ê½¿ÉÒÔ½«ËüµÄÑ¶ºÅÏßÁ¬½Óµ½µçÄÔÑ¶ÁÐ¸·µÄ DCD
   ½Ó½Å¡£ÔÚ SysVinit Ì×¼þÖÐÓÐÒ»¸ö½Ð×ö 'powerd' 
   µÄ³£×¤³ÌÊ½¿ÉÒÔ×·×Ù²¢¼àÊÓ¸ÃÑ¶ºÅÏß£¬µ±Ñ¶ºÅµÄ×´Ì¬¸Ä±äÊ±Ëü»áËÍÒ»¸ö SIGPWR
   µÄÑ¶ºÅ¸ø init ³ÌÊ½£¬Òò´Ë init ±ã¿ÉÒÔ²ÉÈ¡ÊÊµ±µÄÐÐ¶¯ (ÏñÊÇÔÚ 5
   ·ÖÖÓÖ®ááÈÃÏµÍ³¹Ø»ú) ¡£ÈçºÎ½«Ñ¶ºÅÏßÓë UPS ÏàÁ¬ÔÚ "powerd.c"
   ÒÑÓÐËµÃ÷£¬µ«ÎÒ»¹ÊÇÍ¼Ê¾ÈçÏÂÒÔ×öÎª½âÊÍ:


                        +------------------------o  DTR
                        |
                      +---+
                      |   | resistor
                      |   | 10 kilo-Ohm
                      |   |
                      +---+                                To serial port.
                        |
          +-----o-------+------------------------o  DCD
          |             |
          o  UPS        |
        \    relais     |
         \              |
          |             |
          +-----o-------+------------------------o  GND

   »­µÃ»¹¿ÉÒÔÂð?

   Ï£ÍûÕâÑù»áÓÐ°ïÖú¡£

   SysVinit ¿ÉÒÔÔÚ sunsite (»ò¿ÉÄÜÔÚ tsx-11) ÏÂÕÒµ½£¬µµÃûÊÇ 
   SysVinit2.4.tar.z ¡£

   Mike.

   --

   Miquel van Smoorenburg, <miquels@cistron.nl.mugnet.org>
   Ibmio.com: cannot open CONFIG.SYS: file handle broke off.


   >From danny@caution.cistron.nl.mugnet.org Wed Jul 21 14:27:04 1993
   Newsgroups: comp.os.linux
   Subject: Re: UPS interface for Linux?
   From: danny@caution.cistron.nl.mugnet.org (Danny ter Haar)
   Date: Mon, 19 Jul 93 11:02:14
   Distribution: world
   Organization: Cistron Electronics.

   In article <9307174330@caution.cistron.nl.mugnet.org>
   miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg) writes:
   > ÈçºÎ½«Ñ¶ºÅÏßÓë UPS ÏàÁ¬ÔÚ "powerd.c" ÒÑÓÐËµÃ÷£¬
   > µ«ÎÒ»¹ÊÇÍ¼Ê¾ÈçÏÂÒÔ×öÎª½âÊÍ:

   ¸ÃÍ¼Ê¾²¢²»Ê®·ÖÇå³þ£¬Çë¸ÄÓÃÒÔÏÂµÄÍ¼Ê¾!
   >
   >                     +------------------------o  DTR
   >                     |
   >                   +---+
   >                   |   | resistor
   >                   |   | 10 kilo-Ohm
   >                   |   |
   >                   +---+                                To serial port.
   >                     |
   >       +-----o-------+------------------------o  DCD
   >       |
   >       o  UPS
   >     \    relais
   >      \
   >       |
   >       +-----o--------------------------------o  GND
   >

   ÆäÖÐ DTR ½Ó½ÅÊÇ±£³ÖÔÚ¸ßµçÎ»£¬Ôòµ± UPS µÄÍâ½çÊäÈëµçÔ´ÏûÊ§Ê±£¬
   ÄÇ¸ö¿ª¹Ø (relais) »á¹Ø±Õ¡£¶øµçÄÔ±ãÊÇ¼àÊÓ DCD ÊäÈë½Ó½Å£¬µÈÖøËü±ä³ÉµÍµçÎ»¡£
   µ±ÊÂÇé·¢ÉúÊ±Ëü½«»áÆô¶¯¹Ø»ú³ÌÐò ...

   _____
   Danny

   --
   <=====================================================================>
   Danny ter Haar  <dannyth@hacktic.nl> or <danny@cistron.nl.mugnet.org>
   Robins law #103: 'a couple of lightyears can't part good friends'
\end{verbatim}





\subsection{Ñ¶ºÅÀÂÏß·´Ïò·ÖÎö¼°ÐÞ¸Ä power.c\label{hacking}}







\end{document}
