目的: 在支援 ACPI 電源管理的筆記型電腦中監看變壓器供電狀態, 供電中斷後若未能於限制時間內復電則自動關機.
這對 Laptop Server 很有幫助, 前題是電池仍能續電. 03 年買的 Compaq Presario X1034 是我用過最耐用的筆電, 到目前為止所有功能都正常, 且電池仍有 3254mAh 的蓄電量, 拿來當 Server 真有點不捨哩!
使用 acpid
vi /etc/acpi/events/ac_adapter.conf
action=/etc/acpi/actions/ac_adapter.sh |
vi /etc/acpi/actions/ac_adapter.sh
state=/proc/acpi/ac_adapter/AC0/state |
if [ -n "$(grep off $state)" ]; then |
while [ $((countdown--)) - gt 0 ]; do |
if [ -n "$(grep on $state)" ]; then |
logger "Automatic shutdown due to power failure timeout." |
chmod +x /etc/acpi/actions/ac_adapter.sh
/etc/init.d/acpid restart
-
不使用 acpid
vi /usr/local/bin/check_process.sh
if [ -z "$(pgrep ac_monitor.sh)" ]; then |
exec /usr/ local /bin/ac_monitor.sh |
chmod +x /usr/local/bin/check_process.sh
vi /usr/local/bin/ac_monitor.sh
state=/proc/acpi/ac_adapter/AC0/state |
if [ -n "$(grep off $state)" ]; then |
if [ $((countdown--)) - eq 0 ]; then |
logger "Automatic shutdown due to power failure timeout." |
chmod +x /usr/local/bin/ac_monitor.sh
vi /etc/crontab
* * * * * root /usr/local/bin/check_process.sh
http://cha.homeip.net/blog/2010/05/2327.html
沒有留言:
發佈留言