Hey all,
I'm working on software to work with my own external pushbutton power switch. I have the basic code running and working. It processes a button press signal from the external microcontroller, and sends a signal to power off to that MCU when I'm ready to shutdown. The MCU gives me 18 seconds after that pulse to complete the OS shutdown and then turns off the MOSFET. I can also send SIGUSR1 to the process and initiate a shutdown via software request as well.
This all works pretty well. What I'd like to be able to do is get this to happen automatically when the OS is going down with the 'poweroff' command. I don't know if there are any places to determine this either from within the C++ program or within scripts for systemd / rc or whatever.
If there is something that I can hook up to run at poweroff then it's a simple matter of calling "killall -s SIGUSR1 powerswitch" and i'll be able to get the power to turn off automagically when you type the command. It would need to happen before the OS starts killing off processes as it will take up to 100ms to notice that a powerkill request is made.
Anyone know of a way to determine that the OS is going down for poweroff instead of just rebooting?