I'm now having problems specifying the start/stop actions while switching run levels, particularly, from run level 5, to either 6 (reboot) or 0 (powerdown)
With Wheezy, as far as I understand it...
There is a set of rcx.d directories for each run level. Within a run level directory, there are links that point to each particular script to run while entering or exiting that run level.
When entering a run level, any link named with the first letter S is executed, passing the action of "start" to the script. When exiting the run level, any link staring with K is executed, with the action "stop".
Run levels 6 and 0, "exit" during reboot, so links here always start with K, and are passed "stop"
Using these rules, my scripts work fine in Wheezy.
The same scripts do not work in Jessie. In my specific case, the shutdown script is supposed to kill the power in run level 0, but no other run level. However, the script is getting called with "stop" in run level 5, even though it begins with an S, and there is no link starting with K.
I've made an example init script to show what I'm talking about:
Code: Select all
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
#if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
# set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
#fi
### BEGIN INIT INFO
# Provides: StartStopCheck
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: StartStop Action Checker
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d. This example start a
# single forking daemon capable of writing a pid
# file. To get other behavoirs, implemend
# do_start(), do_stop() or other functions to
# override the defaults in /lib/init/init-d-script.
### END INIT INFO
level=`runlevel`
/usr/bin/logger "StartStopCheck: $0 called with $1 at run level $level "
update-rc.d StartStopCheck install
puts links like this in the rc.d directories:
A grep StartStop through syslog over a few shutdown's/reboots looks like this:pi@raspberrypi ~ $ ls /etc/rc*.d/*StartStopCheck
/etc/rc0.d/K01StartStopCheck /etc/rc2.d/S02StartStopCheck /etc/rc4.d/S02StartStopCheck /etc/rc6.d/K01StartStopCheck
/etc/rc1.d/K01StartStopCheck /etc/rc3.d/S02StartStopCheck /etc/rc5.d/S02StartStopCheck
The same StartStop script installed with the same update-rc.d command yields the same rcX.d link structure:(shutdown)
Nov 16 13:06:27 raspberrypi systemd[1]: Stopping LSB: StartStop Action Checker...
Nov 16 13:06:28 raspberrypi logger: StartStopCheck: /etc/init.d/StartStopCheck called with stop at run level N 5
Nov 16 13:06:28 raspberrypi systemd[1]: Stopped LSB: StartStop Action Checker.
(reboot)
Nov 16 13:06:46 raspberrypi systemd[1]: Starting LSB: StartStop Action Checker...
Nov 16 13:06:46 raspberrypi logger: StartStopCheck: /etc/init.d/StartStopCheck called with start at run level unknown
Nov 16 13:06:46 raspberrypi systemd[1]: Started LSB: StartStop Action Checker.
And this grep of syslogpi@raspberrypi ~ $ ls /etc/rc*.d/*StartStopCheck
/etc/rc0.d/K01StartStopCheck /etc/rc2.d/S02StartStopCheck /etc/rc4.d/S02StartStopCheck /etc/rc6.d/K01StartStopCheck
/etc/rc1.d/K01StartStopCheck /etc/rc3.d/S02StartStopCheck /etc/rc5.d/S02StartStopCheck
I have a few questions:Nov 16 19:42:20 raspberrypi logger: StartStopCheck: /etc/init.d/StartStopCheck called with stop at run level 2 6
Nov 16 19:42:43 raspberrypi logger: StartStopCheck: /etc/init.d/StartStopCheck called with start at run level N 2
1) is this the expected new behavior?
2) If so, what are the new rules?
3) Have the run levels changed (jessie ->5 on reboot vs 6 with reboot on Wheezy?)
4) Do my scripts now need to check OS version? What is the best way to handle it?