Re: Files in the /rtc/rc.d/rc*.d directory

From: Bill Unruh (unruh_at_string.physics.ubc.ca)
Date: 02/22/05


Date: 22 Feb 2005 17:08:40 GMT

Laurenz Albe <albe@culturallNOSPAM.com> writes:

>Dani Camps <danicamps81@gmail.com> wrote:
>> What are the files in the /rtc/rc.d/rc*.d directories ? All the files
>> are links to scripts located in /etc/rc.d/init.d, so are these the
>> scripts that are called when the system boots in each of the possible
>> runlevels ? And when the systems shuts down are the scripts in this
>> directory called as well ? Why there are some links starting with K
>> and another ones with S, are ones called during the boot and the
>> others during the shutdown ? Which ones when in that case ? And what
>> about the digital code after the letter S or K, what does it mean ?

>You can get much more information than what I am going to give you
>with a web search for "System V" initialization.

>Like the good article on http://www.freeos.com/articles/3243/

>Most of what you guess is correct.
>The S* scripts ate called when you enter that runlevel, and the
>K* scripts are called when you leave the runlevel (Start and Kill).

No, both the K and S scripts are called when you enter. When you leave you
are in runlevel 6.
See /etc/rc.d/rc

*****************************
# Get first argument. Set new runlevel to this argument.
[ -n "$argv1" ] && runlevel="$argv1"

# Is there an rc directory for this new runlevel?
[ -d /etc/rc$runlevel.d ] || exit 0

# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
   check_runlevel "$i" || continue

   # Check if the subsystem is already up.
   subsys=${i#/etc/rc$runlevel.d/K??}
   rc_splash $subsys
   [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
      || continue

   # Bring the subsystem down.
   if egrep -q "(killproc |action )" $i ; then
      $i stop
   else
      action "Stopping %s: " $subsys $i stop
   fi
done

# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
   check_runlevel "$i" || continue

   # Check if the subsystem is already up.
   subsys=${i#/etc/rc$runlevel.d/S??}
   [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
      && continue

   # If we're in confirmation mode, get user confirmation
   if [ -f /var/run/confirm ]; then
           if [ "$subsys" = dm ]; then
          CONFIRM_DM=1
          continue
      fi
      confirm $subsys
      case $? in
          1) continue;;
          2) rm -f /var/run/confirm;;
      esac
   fi

   rc_splash $subsys

   # Bring the subsystem up.
   if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
      export LC_ALL=C
      exec $i start
   fi

   if [ "$subsys" = "single" ]; then
       rc_splash stop
        fi
   if egrep -q "(daemon |action |success |failure )" $i 2>/dev/null \
         || [ "$subsys" = "single" -o "$subsys" = "local" ]; then
      $i start
   else
      action "Starting %s: " $subsys $i start
   fi

done

******************************************************************

So on entry to a runlevel, first the K scripts are run to kill of anything
that should not be run at that runlevel. Then the S scripts are run to
start up anything that should be started up at that runlevel

>The number after the S or K defines a sequence in which the startup
>or shutdown scripts are called: e.g. you want the network up before
>you start NFS.
>When you boot the machine, you enter the runlevel specified by the
>initdefault entry in /etc/inittab.
>When you shutdown the computer, you go to runlevel 0.
No 6

>There are various menu- and GUI-driven tools that facilitate maintaining
>the symbolic links in the /etc/rc.d directories.



Relevant Pages

  • Re: how do I configure a USB device?
    ... This is what made me think that I only have to run a script to call rcirda ... to /etc/init.d/irda This is the runlevel startscript I mentioned. ... Insserv generates these runlevel scripts by creating symbolic links in the ... as network ...
    (alt.os.linux.suse)
  • Re: Red Hat Enterprise Linux server fails to boot when connected to the network
    ... Can you boot successfully off of CD .. ... running sendmail not setup right.. ... now that you know the runlevel.. ... Aslo would you post all your S scripts in your runlevel? ...
    (RedHat)
  • Re: Rootserver absichern
    ... und Stopscripte je nach Distribution unterschiedlich ist. ... Ältere Ubuntu-Versionen auch. ... "When init changes runlevel first the targets of the links whose names ... followed by the scripts prefixed with an S, ...
    (de.comp.os.unix.linux.misc)
  • Re: Unix without shell
    ... >>So the kernel would boot, it would exec init, init runs this fictional ... You could actually try this using runlevel 4, ... but you can stop the execution of rc scripts by pulling out the ... Besides, what harm would this concept do to Linux, you ...
    (comp.unix.shell)
  • Re: IPTABLES rules lost at reboot.
    ... using the system 5 init scripts. ... program specified is then run for each runlevel. ... When changing runlevels, ... are called in numerical order. ...
    (comp.os.linux.security)