見出し画像

apcupsdの設定

昨日、某職場のサーバクラッシュで急遽再インストールをしてきたわけですが、とにかく再稼働させることに注力してきたため、周辺の細かい色々は後から設定している次第なのです。

まずは、停電時のシャットダウンを自動化してくれているapcupsdの設定。

# pkg install apcupsd

でインストール。次に、/etc/rc.confに

apcupsd_enable="YES"
apcupsd_flags="--term-on-powerfail"

と設定。
UPSはシリアルポート。それに、データ変換ケーブル(自作)を介してUSB-Serial変換ケーブルでサーバにつないでいるため、まずはシリアルポート経由でUPSにアクセスできることを確認しなくちゃいけない。

# cu -s 2400 -l /dev/cuaU0
Connected
--------------------------------------------------------------------------------
American Power Conversion (c) Copyright 2008 All Rights Reserved
Firmware revision: 3, compiled March 31, 2008. 14:56
--------------------------------------------------------------------------------
Model : Smart-UPS RT 2400 XL Manufactured : 02/02/13
Name : *****                  Serial Number : **********
Last battery replacement: 02/02/13 # of battery packs : 002
Battery charge : 100.0% Load : 020.0%
Runtime : 0130 minutes
Input frequency : 49.98 Hz Output frequency : 49.96 Hz
Input voltage : 104.4 VAC Output voltage : 100.0 VAC

-------- Control And Configuration Console -------------------------------------
1- UPS Settings.
2- UPS Control.
?- Help, <ESC>- Logout, <ENTER>- Refresh
>

OK!2400bpsで通信するというのがポイント。
それでは設定ファイルの編集。

♯ vi /usr/local/etc/apcupsd/apcupsd.conf
 
UPSNAME hogehoge
DEVICE /dev/cuaU0
BATTERYLEVEL 5
MINUTES 3
#RETURNCHARGE 15

UPSの残り電池が無くなりかけてシャットダウンプロセスが走った直後に偶然電源が復帰した場合、UPSはシャットダウンしていないけどサーバはシャットダウンしたままで元に戻らない、という事象が発生する可能性があるけれども、デフォルトの設定である #RETURNCHARGE 15 により、15%まで電池が充電されないと復旧しないようになっているのでこれで大丈夫かなという感じですね。
電源が復旧した後のUPS自体の復帰については、いくつかオプションがあるので調べてみました。FreeBSDのデフォルト設定では、

apcupsd_flags="--term-on-powerfail"

になっていますが…。

-k | --killpower | --hibernate
Power down the UPS in hibernate mode after a 10 second delay. This option is normally only used by apcupsd itself to power down the UPS after a system shutdown has almost completed. In hibernate mode, the UPS will again supply power to the system when the utility power returns.

-p --kill-on-powerfail
apcupsd commands the UPS to power down in hibernate mode just before apcupsd starts the system shutdown. This relies on the grace shutdown delay of a Smart-UPS being long enough to allow the system to shutdown completely before the UPS shuts off the power to the system and goes into hibernate mode. This shutdown grace delay is a programmable value stored in a Smart-UPS EEPROM which can be changed using apctest(8). In hibernate mode, the UPS will again supply power to the system when the utility power returns. Refer to apcupsd.conf(5) for an alternative method using the KILLDELAY configuration directive and the only method available when using a Back-UPS or other UPS operating in simple signalling mode.

-t --term-on-powerfail
apcupsd exits immediately when it issues the system shutdown command. This behaviour is useful for those systems where it is not possible to insert apcupsd commands in a halt script to issue the killpower command. Without this option, apcupsd will wait for the SIGTERM signal from the system shutdown process before exiting.

※太字にしたのは私です※

https://linux.die.net/man/8/apcupsd

ふむふむ。じゃあUPS側のEPROMの設定はどうなってたんだべ?

# cu -s 2400 -l /dev/cuaU0
Connected

--------------------------------------------------------------------------------
American Power Conversion (c) Copyright 2008 All Rights Reserved
Firmware revision: 3, compiled March 31, 2008. 14:56
--------------------------------------------------------------------------------
Model : Smart-UPS RT 2400 XL Manufactured : 02/02/13
Name : KomaUPS Serial Number : QS1305341508
Last battery replacement: 02/02/13 # of battery packs : 002
Battery charge : 100.0% Load : 020.0%
Runtime : 0130 minutes
Input frequency : 50.01 Hz Output frequency : 50.01 Hz
Input voltage : 105.1 VAC Output voltage : 100.0 VAC

-------- Control And Configuration Console -------------------------------------

1- UPS Settings.
2- UPS Control.

?- Help, <ESC>- Logout, <ENTER>- Refresh
>
--------UPS Settings.-----------------------------------------------------------

1- Not Available
2- Output frequency : Autosense 50+/-3.0 or 60+/-3.0 Hz
3- Bypass upper line voltage : 110 VAC
4- Bypass lower line voltage : 078 VAC
5- Audible alarm settings : Enable.
6- Low battery warning : 08 minutes
7- Shut Down delay : 090 seconds
8- Synchronized turn on delay : 060 seconds
9- Minimum battery capacity to restart : 15%
A- Battery Test : Every 14 days and on power on
B- Unit is mounted : Vertically
C- UPS Identification : *******
D- Date of last battery replacement : 02/02/13
E- Number of battery packs : 002

?- Help, <ESC>- Previous Menu, <ENTER>- Refresh
>
--------Shut Down delay---------------------------

Currently selected: 090 seconds

Please choose from the following options:

1- 090 seconds
2- 180 seconds
3- 270 seconds
4- 360 seconds
5- 450 seconds
6- 540 seconds
7- 630 seconds
8- 000 seconds

?- Help, <ESC>- Previous Menu, <ENTER>- Refresh
>

シャットダウンディレイは60秒に設定してあった。というか自分がそうしたんだけどね。確か。
ということは、Slaveに繋がっているWindowsサーバなどはもっと電池の残りが多いうちにシャットダウンするようにして、このメインサーバは最後の最後に、残り5%の所でシャットダウンプロセスに入り、そしてapcupsdのオプションは

--kill-on-powerfail

で大丈夫そうだね。
…と思って動かしてみたけど、すぐにプロセスが落ちてしまう…?

apcupsd[38047]: apcupsd FATAL ERROR in smartsetup.c at line 155 PANIC! Cannot communicate with UPS via serial port. Please make sure the port specified on the DEVICE directive is correct, and that your cable specification on the UPSCABLE directive is correct.

ありゃ。
どこがおかしいんだろう…と思って探った結果、 /usr/local/etc/apcupsd/apcupsd.confのUPSCABLEの設定を

UPSCABLE simple

とすればOKなことに気が付きましたよ。

これで上手く動くようになったので、ほっと一息。ふー。

以上。

この記事が気に入ったらサポートをしてみませんか?