5.0-pre2 release
[linux_from_scratch.git] / bootscripts / contrib / rlv / rc
blobe700e5100c0fa1bc51de70654a71b4aa6d194a81
1 #!/bin/sh
2 # Begin $rc_base/init.d/rc - Main Run Level Control Script
4 # Based on rc script from LFS-3.1 and earlier.
5 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
6 #
7 # Modified to use variables below, instead of rc*.d directories with
8 # symbolic links by Neven Has - haski@sezampro.yu
11 # Additional user scripts, not part of the base LFS.
13 # Run level: 3
14 ADD[3]=""
16 # Run level: sysinit
17 ADD[7]=""
20 # Run level: 0
21 STOP[0]="${ADD[3]} ${ADD[7]} sysklogd sendsignals mountfs swap localnet halt"
22 START[0]=""
24 # Run level: 1
25 STOP[1]="sysklogd"
26 START[1]=""
28 # Run level: 2
29 STOP[2]=""
30 START[2]="sysklogd"
32 # Run level: 3
33 STOP[3]=""
34 START[3]="sysklogd ${ADD[3]}"
36 # Run level: 4
37 STOP[4]=""
38 START[4]="sysklogd"
40 # Run level: 5
41 STOP[5]=""
42 START[5]="sysklogd"
44 # Run level: 6
45 STOP[6]="${ADD[3]} ${ADD[7]} sysklogd sendsignals mountfs swap localnet reboot"
46 START[6]=""
48 # Run level: sysinit
49 STOP[7]=""
50 START[7]="swap mountproc checkfs mountfs cleanfs setclock loadkeys localnet \
51 ${ADD[7]}"
54 # There is probably a much better way to do this.
55 should_skip() {
56 for i in $2 ; do if [ $i = $1 ] ; then return 1 ; fi ; done
57 return 0
60 source /etc/sysconfig/rc
61 source $rc_functions
63 trap "" INT QUIT TSTP
65 [ "$1" != "" ] && runlevel=$1
67 if [ "$runlevel" = "" ]
68 then
69 echo "Usage: $0 <runlevel>" >&2
70 exit 1
72 elif [ $runlevel = sysinit ]
73 then
74 runlevel=7
77 previous=$PREVLEVEL
78 [ "$previous" = "" ] && previous=N
80 if [ "$previous" != "N" ]
81 then
82 for i in ${STOP[$runlevel]}
84 script=$rc_base/init.d/$i
86 # check_script_status
87 if [ ! -x $script ]
88 then
89 echo "$script is not executable, skipping"
90 continue
93 if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ]
94 then
95 if [ should_skip $i ${START[$previous]} ] ||
96 [ should_skip $i ${START[7]} ]
97 then
98 $WARNING
99 echo "$i can't be executed because it was"
100 echo "not started in the previous runlevel ($previous)"
101 $NORMAL
102 continue
106 $script stop
107 error_value=$?
109 if [ "$error_value" != "0" ]
110 then
111 print_error_msg
113 done
116 for i in ${START[$runlevel]}
118 script=$rc_base/init.d/$i
120 if [ "$previous" != "N" ]
121 then
122 if [ should_skip $i ${START[$previous]} ] ||
123 [ should_skip $i ${STOP[$runlevel]} ]
124 then
125 continue
129 # check_script_status
130 if [ ! -x $script ]
131 then
132 echo "$script is not executable, skipping"
133 continue
136 $script start
137 error_value=$?
139 if [ "$error_value" != "0" ]
140 then
141 print_error_msg
143 done
145 # End $rc_base/init.d/rc