I am currently looking at the startup and shutdown procedures for ubunut precise pangolin. As far as I understand at shutdown the system switches to runlevel 0 and all scripts with K* are executed with the argument stop and all scripts with S* are executed with the argument start.

Now looking at rc.0 I can see the following scripts:

lrwxrwxrwx  1 root root   16  1. Jan 2000  K20dhcpcd -> ../init.d/dhcpcd
lrwxrwxrwx  1 root root   20  1. Jan 2000  S35networking -> ../init.d/networking
lrwxrwxrwx  1 root root   14  5. Apr 2013  S90halt -> ../init.d/halt
lrwxrwxrwx  1 root root   20  5. Apr 2013  S60umountroot -> ../init.d/umountroot
lrwxrwxrwx  1 root root   18  5. Apr 2013  S40umountfs -> ../init.d/umountfs
lrwxrwxrwx  1 root root   22  5. Apr 2013  S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx  1 root root   17  5. Apr 2013  S30urandom -> ../init.d/urandom
lrwxrwxrwx  1 root root   18  5. Apr 2013  S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx  1 root root   19 26. Aug 2013  K90syslog-ng -> ../init.d/syslog-ng

Which means umountfs, sendsigs and halt will be executed with the argument start.

But looking at the code for example in S90halt I find the following:

case "$1" in
        # No-op
        echo "Error: argument '$1' not supported" >&2
        exit 3
        echo "Usage: $0 start|stop" >&2
        exit 3

I.e. this script does nothing when it gets called with start and only actually halts the system when it is called with stop. I cannot find any reference to this script as a kill script, so when does this happen?

  • It is possibly used in some other runlevel. – muru Jul 16 '14 at 14:30
  • @muru: I looked, but it is nowhere used as K*halt. Furthermore, calling halt (this script stops the system) does not really make sense in other runlevels besides the one used for shutdown. – LiKao Jul 16 '14 at 17:19

According to Ubuntu upstart cookbook:

Ubuntu currently employs a hybrid system where core services are handled by Upstart, but additional services can be run in the legacy SystemV mode. This may seem odd, but consider that there are thousands of packages available in Ubuntu via the Universe and Multiverse repositories and hundreds of services. To avoid having to change every package to work with Upstart, Upstart allows packages to utilize their existing SystemV (and thus Debian-compatible) scripts.

SystemV use run level to manage system startup, shutdown and reboot.

In /etc/init.d are present scripts that handles service stop/start, this scripts follow /etc/init.d/skeleton and are executed by the system every time runlevel change.

Run level are numbered from 0 to 6 and in /etc we found rcX.d folder, one for each level.

In these folders are present symbolic link to scripts in /etc/init.d, as you saw the name of this link are particular: they starts with S or K (S means start and K means Kill) followed by a number and the name of service.

When a system command change the value of runlevel, the scripts in the rcX.d directory are called following the alphabetical order: K scripts with stop parameter, S script with start. This rule does not apply to two runlevels 0 (halt) and 6 (reboot). According to Debian Policy Manual Chapter 9 - The Operating System

In these runlevels, the links with an S prefix are still called after those with a K prefix, but they too are called with the single argument stop.

So that's why the system halt.

This topic is very broad, I hope this little explanation is sufficiently clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.