I have a Raspberry PI running the standard Raspbian distribution. I have this little C program that I need to run at the very end of the shutdown sequence. All it does is send a couple of logical high pulses on a GIPO output to a power supply to tell it to cut the power to the Raspberry board. The shutdown script should be called if, and only if, the system is being powered down but not when the PI is being rebooted or started up.
I have been trying and failing to use update-rc.d to do this. The way I understand the update-rc.d documentation what I have to do is:
Copy my executable (
poweroff.bin
), copy it to /sbin and give it the required permissions and a LSB header:#!/bin/sh ### BEGIN INIT INFO # Provides: poweroff # Required-Start: # Required-Stop: $all # Default-Start: # Default-Stop: 0 # Short-Description: Power off. # Description: Send a power off signal to the PM board. # X-Interactive: false ### END INIT INFO /sbin/poweroff.bin exit 0
Create a script called
poweroff
in /etc/init.d- Run the command sudo update-rc.d
poweroff stop 99 0
.
This will yield me a script: /etc/rc0.d/K99poweroff
which will call /sbin/poweroff.bin
if, and only if the system is being halted.
I have three questions:
- Whenever I run
sudo update-rc.d poweroff stop 99 0 .
it only results in a script called/etc/rc0.d/K01poweroff
being created. What am I doing wrong? what happened to the 99? - What is the significance of the start and stop options during run level 0? Should this script be a K99 or an S99? there seems little point in a start script in run level 0.
- Is run level 0 only used when shutting down? I.e if I do a 'shutdown -r now" does the computer get sent down to run level 0 and then back to runlevel 6?