What is the correct way to shutdown Linux and then destroy the power?

I am running Linux raspberrypi 3.6.11+ on a raspberrypi board with an external power supply. The power switch is disconnected via GPIO.

I want to do "shutdown -h -P now", wait for the system to shutdown (shutdown) and then turn off the power by running the program (killpower) to toggle the corresponding gpio pin. My main goal is to make sure that the filesystem is in a state where it won't get corrupted on power outage.

I tried using runlevel 1 script killproc, which sends SIGTERM (and SIGKILL) to every running process. I wrote killpower to catch SIGTERM, wait 20 seconds and then send the powerkill sequence to gpio. I also changed the killproc script to NOT SIGKILL my mypower power pid, even though it still works after the SIGTERM timeout.

When that didn't work, I found that after running killproc, the /init.d/halt script is run which calls /sbin/halt./sbin/halt also kills all processes with SIGKILL, so I expect my killing power to be killed before 20 seconds. Now I don't see how this approach would work.

I can also see that init can act on the SIGPWR signal (not recommended), but it can do powerwait / powerfail. Is the system able to shutdown at this point? I cannot figure out what these programs are supposed to implement.

I was thinking about setting up another shutdown script in init.d, but I'm confused about which runlevel it should "stop" at (level 1 or level 0).

Is it possible to kill power before the / sbin / halt command is executed as a result of the shutdown command? Is it correct that once / sbin / halt is executed, nothing else will execute?

+3


source to share


1 answer


How can I turn off the Linux port when I logged into it remotely, just use the "poweroff" command. The system then shuts down properly and finally shuts down - nothing more, nothing less, exactly what I want.



0


source







All Articles