acpi – matoken's blog https://matoken.org/blog Is there no plan B? Tue, 03 Feb 2026 10:16:40 +0000 ja hourly 1 https://wordpress.org/?v=7.0.1 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg acpi – matoken's blog https://matoken.org/blog 32 32 電源ボタンで自動シャットダウンを抑制 https://matoken.org/blog/2026/02/03/do-not-auto-shutdown-with-power-button/ https://matoken.org/blog/2026/02/03/do-not-auto-shutdown-with-power-button/#respond Tue, 03 Feb 2026 10:16:37 +0000 https://matoken.org/blog/?p=5203

laptop を少し移動したらシャットダウン処理が走ってしまいました.ログを見ると電源ボタンが押されてシャットダウン処理が走ったようです.
これを抑制しました.

ログはこんな感じです.

リスト 1. syslog より
2026-02-02T06:38:41.358362+09:00 tp-l13 acpid: received input layer event "button/power PBTN 00000080 00000000"
2026-02-02T06:38:41.359609+09:00 tp-l13 acpid: rule from /etc/acpi/events/powerbtn-acpi-support matched
2026-02-02T06:38:41.362438+09:00 tp-l13 acpid: executing action "/etc/acpi/powerbtn-acpi-support.sh"

/etc/systemd/logind.conf の電源ボタンを押したときの HandlePowerKey のコメントを解除して poweroffignore に書き換えて電源ボタンで何もしないようにします.

$ sudo git -C /etc diff HEAD~~ /etc/systemd/logind.conf
diff --git a/systemd/logind.conf b/systemd/logind.conf
index 02ec007..d7e2dbe 100644
--- a/systemd/logind.conf
+++ b/systemd/logind.conf
@@ -25,7 +25,7 @@
 #InhibitDelayMaxSec=5
 #UserStopDelaySec=10
 #SleepOperation=suspend-then-hibernate suspend
-#HandlePowerKey=poweroff
+HandlePowerKey=igore
 #HandlePowerKeyLongPress=ignore
 #HandleRebootKey=reboot
 #HandleRebootKeyLongPress=poweroff

デーモンを再起動して設定を反映します.

$ sudo systemctl restart systemd-logind

電源ボタンを押してシャットダウン処理が走らないのを確認します.

リスト 2. 環境
$ dpkg-query -W systemd acpi
acpi    1.8-1
systemd 259-1
$ lsb_release -dr
Description:    Debian GNU/Linux forky/sid
Release:        n/a
$ arch
x86_64
$ sudo lshw -sanitize -json | jq '."vendor", ."version"'
"LENOVO"
"ThinkPad L13"
]]>
https://matoken.org/blog/2026/02/03/do-not-auto-shutdown-with-power-button/feed/ 0
Debian環境でacpidのログをsyslogに出力する2(acpi event & action) https://matoken.org/blog/2021/07/12/output-acpid-log-to-syslog-part-2-acpi-event-action/ https://matoken.org/blog/2021/07/12/output-acpid-log-to-syslog-part-2-acpi-event-action/#respond Sun, 11 Jul 2021 15:07:13 +0000 http://matoken.org/blog/?p=3301

acpidのイベントをすべてログに出力できるよう設定しました.

しかしちょっと冗長です.ACアダプタの状況だけをロギングするよう設定してみました.

まずACアダプタの抜き差し時のログを確認します.

ACアダプタ切断時
Jul 11 23:05:51 yoga-260 acpid: completed netlink event "ac_adapter ACPI0003:00 00000080 00000000"
ACアダプタ接続時
Jul 11 23:05:55 yoga-260 acpid: received netlink event "ac_adapter ACPI0003:00 00000080 00000001"

manのEXAMPLE を確認します.

man acpidより

EXAMPLE
This example will shut down your system if you press the power button.

Create a file named /etc/acpi/events/power that contains the following:
event=button/power
action=/etc/acpi/power.sh "%e"
Then create a file named /etc/acpi/power.sh that contains the following:
/sbin/shutdown -h now "Power button pressed"
Now,  when  acpid  is  running,  a  press  of  the power button will cause the rule in /etc/acpi/events/power to trigger the script in
/etc/acpi/power.sh.  The script will then shut down the system.

このEXAMPLEを真似してこんなファイルを作成しました.acpidから ac_adapter のイベント実行時にaction に指定されたscript を実行するようにしています.

/etc/acpi/events/ac_event_logging
event=ac_adapter
action=/etc/acpi/ac_event_logging.sh %e

そして呼び出されるscript として以下のファイルを用意.

/etc/acpi/ac_event_logging.sh
#!/bin/sh
case "$4" in
        00000000)
                echo 'AC offline'
                logger -t acpid AC offline
                ;;
        00000001)
                echo 'AC online'
                logger -t acpid AC online
                ;;
esac

このscriptには実行権も付与します.

$ sudo chmod +x /etc/acpi/ac_event_logging.sh

動作を確認するために acpid を再起動します.

$ sudo service acpid restart

この状態でACアダプタを抜き差しするとこんな感じのログが出力されます.

$ sudo tail -f /var/log/syslog | grep acpid:
Jul 11 23:51:10 yoga-260 acpid: received netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 23:51:10 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:10 yoga-260 acpid: completed netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 23:51:10 yoga-260 acpid: received netlink event "ac_adapter ACPI0003:00 00000080 00000000" (1)
Jul 11 23:51:10 yoga-260 acpid: rule from /etc/acpi/events/ac_event_logging matched (2)
Jul 11 23:51:10 yoga-260 acpid: executing action "/etc/acpi/ac_event_logging.sh ac_adapter ACPI0003:00 00000080 00000000" (3)
Jul 11 23:51:10 yoga-260 acpid: AC offline (4)
Jul 11 23:51:10 yoga-260 acpid: action exited with status 0 (5)
Jul 11 23:51:10 yoga-260 acpid: 1 total rule matched
Jul 11 23:51:10 yoga-260 acpid: completed netlink event "ac_adapter ACPI0003:00 00000080 00000000"
Jul 11 23:51:11 yoga-260 acpid: received netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 23:51:11 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:11 yoga-260 acpid: completed netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 23:51:11 yoga-260 acpid: received netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 23:51:11 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:11 yoga-260 acpid: completed netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 23:51:12 yoga-260 acpid: received netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 23:51:12 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:12 yoga-260 acpid: completed netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 23:51:13 yoga-260 acpid: received netlink event "ac_adapter ACPI0003:00 00000080 00000001"
Jul 11 23:51:13 yoga-260 acpid: rule from /etc/acpi/events/ac_event_logging matched
Jul 11 23:51:13 yoga-260 acpid: executing action "/etc/acpi/ac_event_logging.sh ac_adapter ACPI0003:00 00000080 00000001"
Jul 11 23:51:13 yoga-260 acpid: AC online
Jul 11 23:51:13 yoga-260 acpid: action exited with status 0
Jul 11 23:51:13 yoga-260 acpid: 1 total rule matched
Jul 11 23:51:13 yoga-260 acpid: completed netlink event "ac_adapter ACPI0003:00 00000080 00000001"
Jul 11 23:51:13 yoga-260 acpid: received netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 23:51:13 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:13 yoga-260 acpid: completed netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 23:51:13 yoga-260 acpid: received netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 23:51:13 yoga-260 acpid: 0 total rules matched
Jul 11 23:51:13 yoga-260 acpid: completed netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
  1. ACアダプタ切断のログ
  2. ACアダプタ用のeventを見つける
  3. ACアダプタロギング用のscriptを%e を使って引数を渡しつつ実行
  4. ロギング用のscriptでログを出力
  5. action終了

うまく行ったようです :)

ということで他のイベントログを要らないので, /etc/default/acpid を編集して引数を消します.

--- a/default/acpid
+++ b/default/acpid
@@ -1,7 +1,7 @@
 # Options to pass to acpid
 #
 # OPTIONS are appended to the acpid command-line
-OPTIONS="-l"
+#OPTIONS="-l"

 # Linux kernel modules to load before starting acpid
 #

反映するために acpid を再起動します.

$ sudo service acpid restart
$ ps aux | grep [/]sbin/acpid
root     3990040  0.0  0.0   2352   780 ?        Ss   23:59   0:00 /usr/sbin/acpid

再度ログを確認しながらACアダプタの抜き差しをしてログが必要なものだけ出力されているのを確認しました.

sudo tail -f /var/log/syslog | grep acpid:
Jul 12 00:00:04 yoga-260 acpid: AC offline
Jul 12 00:00:07 yoga-260 acpid: AC online

良さそうです :)
サスペンドレジュームも設定してみようかな?

環境
$ dpkg-query -W acpid rsyslog systemd bsdutils
acpid   1:2.0.32-1
bsdutils        1:2.36.1-7
rsyslog 8.2102.0-2
systemd 247.3-5
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
$ arch
x86_64
$ sudo lshw | grep -E '^\ \ \ \ product:|^\ \ \ \ version:'
    product: 20FEA02WJP (LENOVO_MT_20FE_BU_Think_FM_ThinkPad Yoga 260)
    version: ThinkPad Yoga 260
]]>
https://matoken.org/blog/2021/07/12/output-acpid-log-to-syslog-part-2-acpi-event-action/feed/ 0
Debian環境でacpidのログをsyslogに出力する https://matoken.org/blog/2021/07/11/output-acpid-log-to-syslog/ https://matoken.org/blog/2021/07/11/output-acpid-log-to-syslog/#comments Sat, 10 Jul 2021 22:06:39 +0000 http://matoken.org/blog/?p=3298

ThinkPadの電源プラグのOn/Offで以前はイベントがlogに残っていたのですが,電源管理デーモンが動いていて電源の状態が取得できる状態でもいつの頃からか記録されなくなりました.停電した時間がわかって便利だったのでログ期記録できないか確認してみました.

acpitool で電源アダプタの状態を取得
$ acpitool | grep AC
  AC adapter     : online
$ acpitool | grep AC
  AC adapter     : off-line

ThinkPadのFANを制御する方法を調べて思い出したのでacpidのmanやオプションを確認すると, -l, --logevents オプションを使うとすべてのイベントをログに出力してくれるようです.

$ /sbin/acpid -h 2>&1 | grep '\-l,'
  -l, --logevents    Log all event activity.
$ man acpid | grep -i logevents -A1
       -l, --logevents
                   This option tells acpid to log information about all events and actions.

/etc/default/acpid ファイルを編集して,acpid の起動オプションに -l を追加します.

diff --git a/default/acpid b/default/acpid
index c651a78..a6a7add 100644
--- a/default/acpid
+++ b/default/acpid
@@ -1,7 +1,7 @@
 # Options to pass to acpid
 #
 # OPTIONS are appended to the acpid command-line
-#OPTIONS=""
+OPTIONS="-l"

 # Linux kernel modules to load before starting acpid
 #

acpid を再起動してオプションがついているのを確認します.

$ sudo service acpid restart
$ sudo service acpid status
● acpid.service - ACPI event daemon
     Loaded: loaded (/lib/systemd/system/acpid.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-07-11 05:57:54 JST; 44s ago
TriggeredBy: ● acpid.socket
             ● acpid.path
       Docs: man:acpid(8)
   Main PID: 2830732 (acpid)
      Tasks: 1 (limit: 9336)
     Memory: 288.0K
        CPU: 6ms
     CGroup: /system.slice/acpid.service
             └─2830732 /usr/sbin/acpid -l

Jul 11 05:57:54 yoga-260 systemd[1]: Started ACPI event daemon.
Jul 11 05:57:54 yoga-260 acpid[2830732]: starting up with netlink and the input layer
Jul 11 05:57:54 yoga-260 acpid[2830732]: 1 rule loaded
Jul 11 05:57:54 yoga-260 acpid[2830732]: waiting for events: event logging is on
$ ps aux | grep [/]sbin/acpid
root     2830732  0.0  0.0   2352   684 ?        Ss   05:57   0:00 /usr/sbin/acpid -l

acpid に -l オプションのついている状態でsyslogをtailしながら電源を抜き差ししてみると少し可読性が悪いですがログが出力されるのがわかりました.

$ sudo tail -f /var/log/syslog | grep acpid:
Jul 11 05:59:22 yoga-260 acpid: received netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 05:59:22 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:22 yoga-260 acpid: completed netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 05:59:23 yoga-260 acpid: received netlink event "ac_adapter ACPI0003:00 00000080 00000000"
Jul 11 05:59:23 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:23 yoga-260 acpid: completed netlink event "ac_adapter ACPI0003:00 00000080 00000000"
Jul 11 05:59:23 yoga-260 acpid: received netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 05:59:23 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:23 yoga-260 acpid: completed netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 05:59:23 yoga-260 acpid: received netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 05:59:23 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:23 yoga-260 acpid: completed netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 05:59:26 yoga-260 acpid: received netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 05:59:26 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:26 yoga-260 acpid: completed netlink event "battery PNP0C0A:00 00000080 00000001"
Jul 11 05:59:26 yoga-260 acpid: received netlink event "ac_adapter ACPI0003:00 00000080 00000001"
Jul 11 05:59:26 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:26 yoga-260 acpid: completed netlink event "ac_adapter ACPI0003:00 00000080 00000001"
Jul 11 05:59:26 yoga-260 acpid: received netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 05:59:26 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:26 yoga-260 acpid: completed netlink event "ibm/hotkey LEN0068:00 00000080 00006030"
Jul 11 05:59:26 yoga-260 acpid: received netlink event "thermal_zone LNXTHERM:00 00000081 00000000"
Jul 11 05:59:26 yoga-260 acpid: 0 total rules matched
Jul 11 05:59:26 yoga-260 acpid: completed netlink event "thermal_zone LNXTHERM:00 00000081 00000000"

すべてのイベントが出力されるので,ボリュームや,輝度の調整でもこのように書き出されます.

Jul 11 06:01:12 t430s acpid: received input layer event "button/volumeup VOLUP 00000080 00000000 K"
Jul 11 06:01:12 t430s acpid: rule from 1840013[0:0] matched
Jul 11 06:01:12 t430s acpid: notifying client 1840013[0:0]
Jul 11 06:01:12 t430s acpid: 1 total rule matched
Jul 11 06:01:12 t430s acpid: completed input layer event "button/volumeup VOLUP 00000080 00000000 K"
Jul 11 06:01:13 t430s acpid: received input layer event "button/volumedown VOLDN 00000080 00000000 K"
Jul 11 06:01:13 t430s acpid: rule from 1840013[0:0] matched
Jul 11 06:01:13 t430s acpid: notifying client 1840013[0:0]
Jul 11 06:01:13 t430s acpid: 1 total rule matched
Jul 11 06:01:13 t430s acpid: completed input layer event "button/volumedown VOLDN 00000080 00000000 K"
Jul 11 06:01:16 t430s acpid: received input layer event "video/brightnessdown BRTDN 00000087 00000000 K"
Jul 11 06:01:16 t430s acpid: rule from 1840013[0:0] matched
Jul 11 06:01:16 t430s acpid: notifying client 1840013[0:0]
Jul 11 06:01:16 t430s acpid: 1 total rule matched
Jul 11 06:01:16 t430s acpid: completed input layer event "video/brightnessdown BRTDN 00000087 00000000 K"
Jul 11 06:01:16 t430s acpid: received input layer event "video/brightnessup BRTUP 00000086 00000000 K"
Jul 11 06:01:16 t430s acpid: rule from 1840013[0:0] matched
Jul 11 06:01:16 t430s acpid: notifying client 1840013[0:0]
Jul 11 06:01:16 t430s acpid: 1 total rule matched
Jul 11 06:01:16 t430s acpid: completed input layer event "video/brightnessup BRTUP 00000086 00000000 K"

以前よりログが冗長で可読性が悪いですがとりあえず動作しました.これで停電が発生したときに停電発生時間や,短い停電であれば停電間隔が確認できます.

環境1(実際はsid)
$ dpkg-query -W acpid rsyslog systemd
acpid   1:2.0.32-1
rsyslog 8.2102.0-2
systemd 247.3-5
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
$ arch
x86_64
$ sudo lshw | grep -E '^\ \ \ \ product:|^\ \ \ \ version:'
    product: 23533KJ (LENOVO_MT_2353)
    version: ThinkPad T430s
環境2
$ dpkg-query -W acpid rsyslog systemd
acpid   1:2.0.32-1
rsyslog 8.2102.0-2
systemd 247.3-5
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
$ arch
x86_64
$ sudo lshw | grep -E '^\ \ \ \ product:|^\ \ \ \ version:'
    product: 20FEA02WJP (LENOVO_MT_20FE_BU_Think_FM_ThinkPad Yoga 260)
    version: ThinkPad Yoga 260
]]>
https://matoken.org/blog/2021/07/11/output-acpid-log-to-syslog/feed/ 1
NotePCのAC電源接続状況を確認してAC電源が切断されたら時間を表示してサスペンドする https://matoken.org/blog/2021/03/15/note-check-the-ac-power-connection-status-of-the-pc-and-when-the-ac-power-is-cut-off-display-the-time-and-suspend/ https://matoken.org/blog/2021/03/15/note-check-the-ac-power-connection-status-of-the-pc-and-when-the-ac-power-is-cut-off-display-the-time-and-suspend/#respond Mon, 15 Mar 2021 14:11:35 +0000 http://matoken.org/blog/?p=3090 IMG_20210313_181855

大きなバッテリーを裏山で使ってみました.昼過ぎから夕方まで使って目盛り半分くらい.家に帰ってからも使い続けましたがなかなかバッテリ切れになりません.

寝る前に電池が来てる感じがしません.また測り直すのは面倒なので以下のようなscriptを書いて寝ました.

$ while [[ `acpi -a | grep on-line` ]]; do sleep 10;done; echo "AC Off-line! (`date +%T`)" | pee cat "xmessage -file - "& pushbullet ; systemctl suspend
AC Off-line! (02:09:56)

acpiコマンドで電源の状況を確認しました.

$ acpi -a
Adapter 0: on-line
$ acpi -a
Adapter 0: off-line

acpiコマンドがない場合sysを見るといいかもしれません.acpidがない場合は無理かな?

$ while [[ `cat /sys/class/power_supply/AC/online` == 1 ]]; do sleep 10;done; echo "AC Off-line! (`date +%T`)" | pee cat "xmessage -file - "& pushbullet ; systemctl suspend

10秒毎に電源状況を確認してAC電源がOffになったらコンソールとXとPushBulletにメッセージを送信してサスペンドするようにしました.

てことでPCの動作状況にもよるでしょうが今回は約12時間動作しました.

今回バッテリー(3.7V DC)からAC 100Vに変換,更にDC(20V)変換しているので変換効率が悪そうです.DC12V出力も出来るようなのでそこからDC-DC変換するようにすると効率よくなってさらに時間が伸びそうな気がします.

環境
$ sudo lshw -c system -sanitize | head
computer
    description: Notebook
    product: 23533KJ (LENOVO_MT_2353)
    vendor: LENOVO
    version: ThinkPad T430s
    serial: [REMOVED]
    width: 64 bits
    capabilities: smbios-2.7 dmi-2.7 smp vsyscall32
    configuration: administrator_password=disabled chassis=notebook family=ThinkPad T430s power-on_password=disabled sku=LENOVO_MT_2353 uuid=[REM
OVED]
  *-pnp00:00
$ dpkg-query -W acpi x11-utils
acpi    1.7-1.1
x11-utils       7.7+5
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
]]>
https://matoken.org/blog/2021/03/15/note-check-the-ac-power-connection-status-of-the-pc-and-when-the-ac-power-is-cut-off-display-the-time-and-suspend/feed/ 0