Execution order of runlevel scripts

5,909

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.

Share:
5,909

Related videos on Youtube

Philipp
Author by

Philipp

Updated on September 18, 2022

Comments

  • Philipp
    Philipp almost 2 years

    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.

  • Dani_l
    Dani_l almost 10 years
    the contradiction concerns the order of K scripts. The debian authoritative manual debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit claims both S and K are ascending, yet the sentence claims different order for S and K. Of course this is implementation specific.
  • Philipp
    Philipp almost 10 years
    I'm using busybox. The actual script launcher is /etc/init.d/rc and it contains the following comment. Optimization feature: A startup script is _not_ run when the service was running in the previous runlevel... So this answers my question. Thanks again.