電源ボタンを押したときにsystemdを使用してスクリプトを実行できますか?

電源ボタンを押したときにsystemdを使用してスクリプトを実行できますか?

周りを見回しましたが、何も見つかりませんでした。私が知っている人はいつも何に満足していましたか?ログインプロファイル提供されていますが、面白い部分は次のとおりですman logind.conf

HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch=, HandleLidSwitchDocked=
       Controls how logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", and "lock". If "ignore", logind will never handle these keys. If
       "lock", all running sessions will be screen-locked; otherwise, the specified action will be taken in the respective event. Only input devices with the
       "power-switch" udev tag will be watched for key/lid switch events.  HandlePowerKey= defaults to "poweroff".  HandleSuspendKey= and HandleLidSwitch= default to
       "suspend".  HandleLidSwitchDocked= defaults to "ignore".  HandleHibernateKey= defaults to "hibernate". If the system is inserted in a docking station, or if
       more than one display is connected, the action specified by HandleLidSwitchDocked= occurs; otherwise the HandleLidSwitch= action occurs.

       A different application may disable logind's handling of system power and sleep keys and the lid switch by taking a low-level inhibitor lock
       ("handle-power-key", "handle-suspend-key", "handle-hibernate-key", "handle-lid-switch"). This is most commonly used by graphical desktop environments to take
        over suspend and hibernation handling, and to use their own configuration mechanisms. If a low-level inhibitor lock is taken, logind will not take any action
       when that key or switch is triggered and the Handle*= settings are irrelevant.

次に、ここで興味深い部分を繰り返します。

システムの電源オフやサスペンドなどの操作をトリガーするために、ログインがシステムの電源、スリープキー、およびカバースイッチを処理する方法を制御します。 「無視」、「電源オフ」、「再起動」、「停止」、「kexec」、「一時停止」、「休止状態」、「ハイブリッド省電力」、「ロック」のいずれかです。

それとも私が間違っていると思いますか?これは電源ボタンではなくキーボードキーだけですか?

とにかく以前はacpiを使用すると簡単だったので、交換してください。電源ボタンのスクリプトには/usr/lib/acpid/systemdと同じものがありますか?

参考(重要):キーボードの電源キーを押したときにsystemdを使用してスクリプトを実行するには?誤って重複としてマークされたため、重複ではありません。systemdでスクリプトを実行するために電源ボタンの終了動作を変更する方法私の質問には答えません。これは、電源ボタンではなくキーボードで電源キーを管理するためです。

電源ボタン

@TooTeaが提案したように、シェルに組み込まれたボタンは、/dev/input/by-path/platform-i8042-serio-0-eventのようなものがないことを確認してから、キーボードのボタンを押すことで処理できます。 kbdファイルを使用して押したキーを監視すると、私の質問には間違いなく答えません。

ベストアンサー1

最後に解決策を見つけましたが、幸運にもopenboxを使用しています。

私の場合は、LXDEで次のセクションを編集して~/.config/openbox/lxde-rc.xml追加<keyboard> ... </keyboard>します。

  <keybind key="XF86PowerOff">
      <action name="Execute">
        <command>command or script to run</command>
      </action>
  </keybind>

たとえば、テストのために「電源を切るにはタップします」というポップアップを開きました。

  <keybind key="XF86PowerOff">
      <action name="Execute">
        <command>zenity --info --text="Power off pressed"</command>
      </action>
  </keybind>

次に、ターミナルタイプでopenbox-lxde --reconfigureタワーケースの電源ボタンを押すと、次のメッセージが表示されます。

ここに画像の説明を入力してください。

編集:言及するのを忘れました(必須かどうかはわかりません)。シャットダウンボタンを空白のままにしました。これを確認するには、スタートメニュー - >システム - >基本設定 - >「電源マネージャ」に行き、「電源ボタンがいつ動作するかを確認してください」 「押された」が「何もしない」に設定されています。

ここに画像の説明を入力してください。

おすすめ記事