Okay, so I did more research and after understanding it more I know the udev rules aren’t the place to execute scripts on button press - that would require the button device to appear/disappear upon press.
I found the updated documentation on the gpio-shutdown overlay, which now includes extra information about implementing the shutdown without systemd:
Alternatively this event can be handled also on systems without
systemd, just by traditional SysV init daemon. KEY_POWER event
(keycode 116) needs to be mapped to KeyboardSignal on console
and then kb::kbrequest inittab action which is triggered by
KeyboardSignal from console can be configured to issue system
shutdown. Steps for this configuration are:
Add following lines to the /etc/console-setup/remap.inc file:
# Key Power as special keypress
keycode 116 = KeyboardSignal
Then add following lines to /etc/inittab file:
# Action on special keypress (Key Power)
kb::kbrequest:/sbin/shutdown -t1 -a -h -P now
And finally reload configuration by calling following commands:
# dpkg-reconfigure console-setup
# service console-setup reload
# init q
The problem is that it’s not really init system agnostic - it requires objects which are not present in the systemd-based HassOS like /etc/inittab
file or /etc/console-setup/
directory. The other directories I could think of (/etc/init.d
, /etc/rc.d
) are also non-existent in /etc
directory of HassOS.
I’m wondering - what could be the impact of adding systemd-logind to the HassOS after all? According to its description it’s responsible for things like:
- Keeping track of users and sessions, their processes and their idle state.
- Generating and managing session IDs.
- Providing polkit-based access for users for operations such as system shutdown or sleep
- Implementing a shutdown/sleep inhibition logic for applications
- Handling of power/sleep hardware keys
- Multi-seat management
- Session switch management
- Device access management for users
- Automatic spawning of text logins (gettys) on virtual console activation and user runtime directory management
I think having the standardized power key handling would be good addition to HassOS - I could even try to make a pull request for its Github repository which would add systemd-logind, since I worked with Buildroot before. However, the fact it does so many other things which are not vital for the HassOS operation and could potentially interfere with its current behavior (polkit) makes me wonder if there is a more lightweight solution, ideally such one that could be deployed with the CONFIG USB for the true out-of-box experience that doesn’t require tinkering with the system files too much.