From 8ffcd3efb99d6ac2fd32c6f9a67eb3b8e840aa90 Mon Sep 17 00:00:00 2001 From: Johannes Truschnigg Date: Wed, 10 Oct 2018 11:34:06 +0200 Subject: [PATCH] Implement basic ACPI shutdown support via busybox acpid (#209) On systems where ACPI support is present as inidcated by the presence of /proc/acpi (e.g. on OVA compatible hypervisors), we want to properly shut down the system when the power button is pressed (or the hypervisor simulates this kind of event to the guest machine that executes hassos). This changeset provides the following basic infrastructure for this feature to work as expected: * a systemd service to start acpid, if ACPI support can be assumed * an acpid configuration directory * a trivial shutdown script to invoke when a PWR event is registered --- .../rootfs-overlay/etc/acpi/PWRF/00000080 | 7 +++++++ .../multi-user.target.wants/busybox-acpid.service | 1 + .../usr/lib/systemd/system/busybox-acpid.service | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100755 buildroot-external/rootfs-overlay/etc/acpi/PWRF/00000080 create mode 120000 buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/busybox-acpid.service create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/busybox-acpid.service diff --git a/buildroot-external/rootfs-overlay/etc/acpi/PWRF/00000080 b/buildroot-external/rootfs-overlay/etc/acpi/PWRF/00000080 new file mode 100755 index 000000000..08ef0f7ad --- /dev/null +++ b/buildroot-external/rootfs-overlay/etc/acpi/PWRF/00000080 @@ -0,0 +1,7 @@ +#!/bin/sh + +# This script is exec()d by acpid when an ACPI event signals the power button +# to have been pressed. + +echo "System power button was pressed - shutting down..." +exec /bin/systemctl poweroff diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/busybox-acpid.service b/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/busybox-acpid.service new file mode 120000 index 000000000..58ebeea6d --- /dev/null +++ b/buildroot-external/rootfs-overlay/etc/systemd/system/multi-user.target.wants/busybox-acpid.service @@ -0,0 +1 @@ +/usr/lib/systemd/system/busybox-acpid.service \ No newline at end of file diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/busybox-acpid.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/busybox-acpid.service new file mode 100644 index 000000000..77aa28f5e --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/busybox-acpid.service @@ -0,0 +1,12 @@ +[Unit] +Description=acpid (busybox) +RefuseManualStop=true +ConditionPathIsDirectory=/proc/acpi + +[Service] +Type=simple +ExecStart=/sbin/acpid -d + +[Install] +After=local-fs.target +WantedBy=multi-user.target