Where can I hook into linux to add custom soft power down?
That's the question. Here's why I need to know:
I am trying to make a rapsberry pi soft power-down. More precisely I want the pi to be switched off (power supply disconnected) when put into Runlevel 0 (aka sudo poweroff
).
I know that the Pi doesn't have the hardware to do this so I'm going to build some custom electronics which will toggle the power supply to the Pi. I'm going to use a GPIO pin which will allow software on the pi to signal my electronics and toggle (off) and have a button to toggle it back on.
So far, so good.
My problem is WHERE do I put the code to send a signal through the GPIO?
Two things spring to mind:
- Maybe I should write a program and wrap it in a script in
/etc/init
forsystemd
to use. - Maybe I need to write a kernel module. But if so where / how do I hook in to the shutdown sequence?
I can't just guess. If I get this wrong the PI will power-down too soon and not finish shutting down linux. But I've spent hours on google and not found documentation for this.
I know this is possible because it's exactly what happens with ACPI. When a PC / Laptop shuts down, the motherboard will signal the powersupply to cut [most of] the power. Something in the operating system (linux) must be triggering this. So where does ACPI soft off hook into the shutdown sequence on linux?