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.binexit 0Create a script called poweroff in /etc/init.dRun 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?
Creating a shutdown only script with update-rc.d
linux;init script;init;init.d
The numbering requested is ignored by dependency based meta init systems. you have the wrong provides!. The critical clue is from another script. lets take a look at umountroot:### BEGIN INIT INFO# Provides:          umountroot# Required-Start:# Required-Stop:# Should-Stop:       halt reboot kexec# Default-Start:# Default-Stop:      0 6# Short-Description: Mount the root filesystem read-only.### END INIT INFOLets look closely at the Should-Stop line. notice that it depends on halt, not poweroff. We can see this definitively by looking at debian's  halt script:### BEGIN INIT INFO# Provides:          halt# Required-Start:# Required-Stop:# Default-Start:# Default-Stop:      0# Short-Description: Execute the halt command.# Description:### END INIT INFONote that the update script will still not call it K99, but will probably call it  something like K15 unless you have a very complicated set of dependencies. but if you change your provides line to halt, it should work.