Appendix C
Linux /etc/rc.d/rc script program listing
1 #!/bin/bash
2 #
3 # rc This file is responsible for starting/stopping
4 # services when the runlevel changes. It is also
5 # responsible for the very first setup of basic
6 # things, such as setting the hostname.
7 #
8 # Original Author:
9 # Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
10 #
11
12 # Source function library.
13 . /etc/rc.d/init.d/functions
14
15 # Now find out what the current and what the previous runlevel are.
16 argv1="$1"
17 set `/sbin/runlevel`
18 runlevel=$2
19 previous=$1
20 export runlevel previous
21
22 # See if we want to be in user confirmation mode
23 if [ "$previous" = "N" ]; then
24 if grep -i confirm /proc/cmdline >/dev/null ; then
25 CONFIRM=yes
26 else
27 CONFIRM=
28 fi
29 fi
30
31 # Get first argument. Set new runlevel to this argument.
32 [ "$1" != "" ] && runlevel="$argv1"
33
34 # Tell linuxconf what runlevel we are in
35 [ -d /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
36
37 # Is there an rc directory for this new runlevel?
38 if [ -d /etc/rc.d/rc$runlevel.d ]; then
39 # First, run the KILL scripts.
40 for i in /etc/rc.d/rc$runlevel.d/K*; do
41 # Check if the script is there.
42 [ ! -f $i ] && continue
43
44 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
45 [ "${i%.rpmsave}" != "${i}" ] && continue
46 [ "${i%.rpmorig}" != "${i}" ] && continue
47 [ "${i%.rpmnew}" != "${i}" ] && continue
48
49 # Check if the subsystem is already up.
50 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
51 [ ! -f /var/lock/subsys/$subsys ] && \
52 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
53
54 # Bring the subsystem down.
55 if egrep -q "(killproc |action )" $i ; then
56 $i stop
57 else
58 action "Stopping $subsys" $i stop
59 fi
60 done
61
62 # Now run the START scripts.
63 for i in /etc/rc.d/rc$runlevel.d/S*; do
64 # Check if the script is there.
65 [ ! -f $i ] && continue
66
67 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
68 [ "${i%.rpmsave}" != "${i}" ] && continue
69 [ "${i%.rpmorig}" != "${i}" ] && continue
70 [ "${i%.rpmnew}" != "${i}" ] && continue
71
72 # Check if the subsystem is already up.
73 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
74 [ -f /var/lock/subsys/$subsys ] || \
75 [ -f /var/lock/subsys/${subsys}.init ] && continue
76
77 # If we're in confirmation mode, get user confirmation
78 [ -n "$CONFIRM" ] &&
79 {
80 confirm $subsys
81 case $? in
82 0)
83 :
84 ;;
85 2)
86 CONFIRM=
87 ;;
88 *)
89 continue
90 ;;
91 esac
92 }
93
94 # Bring the subsystem up.
95 if egrep -q "(daemon |action )" $i ; then
96 $i start
97 else
98 if [ "$subsys" = "halt" -o "$subsys" = "reboot" -o "$subsys" = "single" ]; then
99 $i start
100 else
101 action "Starting $subsys" $i start
102 fi
103 fi
104 done
105 fi
|
|