Apcupsd
サーバを稼動させていると常時電源が入っているため予期せぬ停電や雷によるサージというのが非常に怖い。
対策として通常はUPSなどを導入するのだが、APC社製のUPSであればフリーウェアのマネージメントソフトウェアがある。
マネージメントソフトを導入すると停電後にサーバをシャットダウンさせたり電源の空き容量を確認することが可能になる。
KAJUKAJU.netではUPSにAPC社のSmart-UPS 700、シリアルケーブルに940-0024C(黒色)を使用している。
シリアルケーブルには複数の種類があるが一般的なのは以下の二つ。
・940-0020B(灰色)
・940-0024C(黒色)
今回はブラウザ経由でUPSの状態を確認可能にするためにオプションを設定している。
$ wget http://jaist.dl.sourceforge.net/sourceforge/apcupsd/apcupsd-3.12.3.tar.gzApcupsdの設定を行う。
$ tar xvzf apcupsd-3.12.3.tar.gz
$ cd apcupsd-3.12.3
$ ./configure --enable-cgi --with-cgi-bin=/etc/apcupsd/cgi
$ make
# make install
/etc/apcupsd/apcupsd.conf
UPSCABLE 940-0024C起動スクリプトを作成する。
UPSTYPE apcsmart
DEVICE /dev/ttyS0
LOCKFILE /var/lock
/etc/rc.d/init.d/apcupsd
#! /bin/sh
#
# apcupsd This shell script takes care of starting and stopping
# the apcupsd UPS monitoring daemon.
#
# chkconfig: 2345 60 99
# description: apcupsd monitors power and takes action if necessary
#
APCPID=/var/run/apcupsd.pid
if test -f /etc/whitebox-release ; then
f=/etc/whitebox-release
else
f=/etc/redhat-release
fi
if test `cat $f | grep release |\
cut -f 3 -d ' '`x = "Enterprise"x ; then
DISTVER="Enterprise "`cat $f | grep release |\
cut -f 6 -d ' '`
else
DISTVER=`cat /etc/redhat-release | grep release |\
cut -f 5 -d ' '`
fi
# Source function libarary
. /etc/rc.d/init.d/functions
case "$1" in
start)
rm -f /etc/apcupsd/powerfail
rm -f /etc/nologin
echo -n "Starting UPS monitoring:"
daemon /sbin/apcupsd -f /etc/apcupsd/apcups
d.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/apcupsd
;;
stop)
echo -n "Shutting down UPS monitoring:"
killproc apcupsd
echo
rm -f $APCPID
rm -f /var/lock/subsys/apcupsd
;;
restart)
$0 stop
sleep 15
$0 start
;;
status)
/sbin/apcaccess status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
起動スクリプトを登録する。
# chmod 755 /etc/rc.d/init.d/apcupsd # /sbin/chkconfig --add apcupsd # /sbin/chkconfig --list apcupsd 0:オフ 1:オフ 2:オン 3:オン 4:オン 5:オン 6:オフ起動する。
# /sbin/service apcupsd start Starting UPS monitoring: [ OK ]確認。
# ps -aux |grep apc root 7708 0.0 0.2 11904 728 ? S 19:56 0:00 /sbin/apcupsd -f /etc/apcupsd/apcupsd.conf # netstat -an |grep 3551 tcp 0 0 0.0.0.0:3551 0.0.0.0:* LISTEN起動時のログ。
# tail /var/log/apcupsd.eventsコマンドを実行してUPSのステータスを確認する。
Mon May 01 19:57:02 JST 2006 apcupsd 3.12.3 (26 April 2006) redhat startup succeeded
# tail /var/log/messages
May 1 19:56:46 boris apcupsd: apcupsd起動 succeeded
May 1 19:57:02 boris apcupsd[7708]: NIS server startup succeeded
May 1 19:57:02 boris apcupsd[7708]: apcupsd 3.12.3 (26 April 2006) redhat startup succeeded
下記のようにいろいろな情報が取得できればOK。
# /sbin/apcaccess status APC : 001,052,1229 DATE : Mon May 01 19:00:39 JST 2006 HOSTNAME : boris RELEASE : 3.12.3 VERSION : 3.12.3 (26 April 2006) redhat UPSNAME : UPS_IDEN CABLE : APC Cable 940-0024C MODEL : SMART-UPS 700 UPSMODE : Stand Alone STARTTIME: Mon May 01 19:00:21 JST 2006 STATUS : ONLINE LINEV : 102.0 Volts LOADPCT : 24.9 Percent Load Capacity BCHARGE : 100.0 Percent TIMELEFT : 23.0 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds MAXLINEV : 102.0 Volts MINLINEV : 101.4 Volts OUTPUTV : 102.0 Volts SENSE : High DWAKE : 060 Seconds DSHUTD : 180 Seconds DLOWBATT : 05 Minutes LOTRANS : 081.0 Volts HITRANS : 114.0 Volts RETPCT : 000.0 Percent ITEMP : 44.1 C Internal ALARMDEL : 5 seconds BATTV : 27.3 Volts LINEFREQ : 50.0 Hz LASTXFER : Automatic or explicit self test NUMXFERS : 0 TONBATT : 0 seconds CUMONBATT: 0 seconds XOFFBATT : N/A SELFTEST : NO STESTI : 336 STATFLAG : 0x07000008 Status Flag DIPSW : 0x00 Dip Switch REG1 : 0x00 Register 1 REG2 : 0x00 Register 2 REG3 : 0x00 Register 3 MANDATE : 10/13/99 SERIALNO : NS9942330433 BATTDATE : 10/13/99 NOMOUTV : 100 NOMBATTV : 24.0 EXTBATTS : 0 FIRMWARE : 50.12S.A APCMODEL : GWA END APC : Mon May 01 19:01:23 JST 2006ブラウザでApcupsdにアクセスするためにApacheの設定を行う。
/usr/local/apache2/conf/httpd.conf
ScriptAlias /apcupsd/ "/etc/apcupsd/cgi/"
ブラウザでhttp://site/apcupsd/multimon.cgiにアクセスしアクセスできればOK。
