Linux – Execution order of runlevel scripts

linuxrunlevelstartup-scripts

My runlevel 0 scripts in /etc/rc0.d, which should be executed when stopping are for example

  1. K05foo -> …
  2. K10bar -> …
  3. K80baz -> …
  4. S10somemore -> …
  5. S90halt -> …

Is it correct, that the excution order is as listed above, that is

  1. First all Kills, in ascending priority order
  2. Then all Starts, in ascending priority order
  3. All this, independently of the runlevel to which we switch (S,0-6)
  4. All scripts always get called (ie. there is no additional checks which would prevent a script to be called, for example whether in the previous runlevel that script was in fact started)

I'm confused because on my embedded system some of the scripts don't seem to get executed, and that page says

S20 link is started before a S91 and and K91 is kill before K20.

which contradicts my text above.

Best Answer

Answering my own question, for the sake of completness:

I'm using busybox on an OpenEmbedded system. The rc script in /etc/init.d/rc has the following behavior:

  • In the target runlevel, all Kills are executed before all Starts
  • All scripts are executed in ascending priority order
  • But: Starts are only executed if in the previous runlevel there wasn't also an equivalent start (ie. it's newly starting)
  • And, if the target runlevel is 0 (halt) or 6 (reboot), then starts are actually executed as Kills - ie "stop" is passed as argument. But still after all Kills, and still not if an equivalent start existed in the previous runlevel.

Additionally, what bit me was that shutdown now actually switches to runlevel 1 and not runlevel 0. You have to use halt or powerofffor runlevel 0. So my scripts in rc0.d where not really executed, only the ones which happened to also be in rc1.d.