3 # rc This file is responsible for starting/stopping
4 # services when the runlevel changes.
6 # Optimization feature:
7 # A startup script is _not_ run when the service was
8 # running in the previous runlevel and it wasn't stopped
9 # in the runlevel transition (most Debian services don't
10 # have K?? links in rc{1,2,3,4,5} )
12 # Author: Miquel van Smoorenburg <miquels@cistron.nl>
13 # Bruce Perens <Bruce@Pixar.com>
15 # Version: @(#)rc 2.78 07-Nov-1999 miquels@cistron.nl
22 # Start script or program.
35 # Ignore CTRL-C only in this shell, so we can interrupt subprocesses.
36 trap ":" INT QUIT TSTP
38 # Set onlcr to avoid staircase effect.
41 # Now find out what the current and what the previous runlevel are.
44 # Get first argument. Set new runlevel to this argument.
45 [ "$1" != "" ] && runlevel=$1
46 if [ "$runlevel" = "" ]
48 echo "Usage: $0 <runlevel>" >&2
52 [ "$previous" = "" ] && previous=N
54 export runlevel previous
56 # Is there an rc directory for this new runlevel?
57 if [ -d /etc/rc$runlevel.d ]
59 # First, run the KILL scripts.
62 for i in /etc/rc$runlevel.d/K[0-9][0-9]*
64 # Check if the script is there.
65 [ ! -f $i ] && continue
71 # Now run the START scripts for this runlevel.
72 for i in /etc/rc$runlevel.d/S*
74 [ ! -f $i ] && continue
76 if [ $previous != N ] && [ $previous != S ]
79 # Find start script in previous runlevel and
80 # stop script in this runlevel.
82 suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
83 stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix
84 previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
86 # If there is a start script in the previous level
87 # and _no_ stop script in this level, we don't
88 # have to re-start the service.
90 [ -f $previous_start ] && [ ! -f $stop ] && continue