source: chapter07/rc.xml@ 793c2f7

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.0 6.1 6.1.1 6.3 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk v3_0 v3_1 v3_2 v3_3 v4_0 v4_1 v5_0 v5_1 v5_1_1 xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 793c2f7 was b822811, checked in by Mark Hymers <markh@…>, 23 years ago

XML changes

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@827 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 6.8 KB
Line 
1<sect1 id="ch07-rc">
2<title>Creating the rc script</title>
3
4<para>The first main boot script is the <filename>/etc/init.d/rc</filename>
5script. Create the <filename>/etc/init.d/rc</filename> script by running the
6following command:</para>
7
8<para><screen><userinput>cat &gt; rc &lt;&lt; "EOF"</userinput>
9#!/bin/sh
10# Begin /etc/init.d/rc
11#
12# By Jason Pearce - jason.pearce@linux.org
13# Modified by Gerard Beekmans - gerard@linuxfromscratch.org
14# print_error_msg based on ideas by Simon Perreault -
15# nomis80@videotron.ca
16
17#
18# Include the functions declared in the /etc/init.d/functions file
19#
20
21source /etc/init.d/functions
22
23#
24# The print_error_msg function prints an error message when an unforeseen
25# error occurred that wasn't trapped for some reason by a evaluate_retval
26# call or error checking in different ways.
27
28print_error_msg()
29{
30
31 echo
32 $FAILURE
33 echo -n "You should not read this error message. It means "
34 echo "that an unforeseen error "
35 echo -n "took place and subscript $i exited with "
36 echo "a return value "
37 echo -n "of $error_value for an unknown reason. If you're able "
38 echo "to trace this error down "
39 echo -n "to a bug in one of the files provided by this book, "
40 echo "please be so kind to "
41 echo -n "inform us at lfs-discuss@linuxfromscratch.org"
42 $NORMAL
43 echo
44 echo
45 echo "Press a key to continue..."
46 read
47}
48
49#
50# If you uncomment the debug variable below none of the scripts will be
51# executed, just the script name and parameters will be echo'ed to the
52# screen so you can see how the scripts are called by rc.
53#
54
55# Un-comment the following for debugging.
56# debug=echo
57
58#
59# Start script or program.
60#
61startup() {
62
63 $debug $*
64
65}
66
67#
68# Ignore CTRL-C only in this shell, so we can interrupt subprocesses.
69#
70
71trap ":" INT QUIT TSTP
72
73#
74# Now find out what the current and what the previous runlevel are. The
75# $RUNLEVEL variable is set by init for all it's children. This script
76# runs as a child of init.
77#
78
79runlevel=$RUNLEVEL
80
81#
82# Get first argument. Set new runlevel to this argument. If no runlevel
83# was passed to this script we won't change runlevels.
84#
85
86[ "$1" != "" ] &amp;&amp; runlevel=$1
87if [ "$runlevel" = "" ]
88then
89 echo "Usage: $0 &lt;runlevel&gt;" &gt;&amp;2
90 exit 1
91fi
92
93#
94# The same goes for $PREVLEVEL (see above for $RUNLEVEL). previous will
95# be set to the previous run level. If $PREVLEVEL is not set it means
96# that there is no previous runlevel and we'll set previous to N.
97#
98
99previous=$PREVLEVEL
100[ "$previous" = "" ] &amp;&amp; previous=N
101
102export runlevel previous
103
104#
105# Is there an rc directory for the new runlevel?
106#
107
108if [ -d /etc/rc$runlevel.d ]
109
110then
111
112#
113# If so, first collect all the K* scripts in the new run level.
114#
115
116 if [ $previous != N ]
117 then
118 for i in /etc/rc$runlevel.d/K*
119 do
120 [ ! -f $i ] &amp;&amp; continue
121
122#
123# the suffix variable will contain the script name without the leading
124# Kxxx
125#
126
127 suffix=${i#/etc/rc$runlevel.d/K[0-9][0-9][0-9]}
128#
129# If there is a start script for this K script in the previous runlevel
130# determine what it's full path is
131#
132 previous_start=/etc/rc$previous.d/S[0-9][0-9][0-9]$suffix
133#
134# If there was no previous run level it could be that something was
135# started in rcS.d (sysinit level) so we'll determine the path for that
136# possibility as well.
137#
138
139 sysinit_start=/etc/rcS.d/S[0-9][0-9][0-9]$suffix
140
141#
142# Stop the service if there is a start script in the previous run level
143# or in the sysinit level. If previous_start or sysinit_start do not
144# exist the 'continue' command is run which causes the script to abort
145# this iteration of the for loop and continue with the next iteration.
146# This boils down to that it won't run the commands after the next two
147# lines and start over from the top of this for loop. See man bash for
148# more info on this.
149#
150
151 [ ! -f $previous_start ] &amp;&amp;
152 [ ! -f $sysinit_start ] &amp;&amp; continue
153
154#
155# If we found previous_start or sysinit_start, run the K script
156#
157
158 startup $i stop
159 error_value=$?
160#
161# If the return value of the script is not 0, something went wrong with
162# error checking inside the script. the print_error_msg function will be
163# called and the message plus the return value of the K script will be
164# printed to the screen
165#
166
167 if [ $error_value != 0 ]
168 then
169 print_error_msg
170 fi
171
172 done
173 fi
174
175#
176# Now run the START scripts for this runlevel.
177#
178
179 for i in /etc/rc$runlevel.d/S*
180 do
181 [ ! -f $i ] &amp;&amp; continue
182
183 if [ $previous != N ]
184 then
185#
186# Find start script in previous runlevel and stop script in this
187# runlevel.
188#
189
190 suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9][0-9]}
191 stop=/etc/rc$runlevel.d/K[0-9][0-9][0-9]$suffix
192 previous_start=/etc/rc$previous.d/S[0-9][0-9][0-9]$suffix
193#
194# If there is a start script in the previous level and no stop script in
195# this level, we don't have to re-start the service; abort this
196# iteration and start the next one.
197#
198
199 [ -f $previous_start ] &amp;&amp; [ ! -f $stop ] &amp;&amp;
200 continue
201 fi
202
203 case "$runlevel" in
204 0|6)
205
206#
207# levels 0 and 6 are halt and reboot levels. We don't really start
208# anything here so we call with the 'stop' parameter
209#
210
211 startup $i stop
212 error_value=$?
213#
214# If the return value of the script is not 0, something went wrong with
215# error checking inside the script. the print_error_msg function will be
216# called and the message plus the return value of the K script will be
217# printed to the screen
218#
219
220 if [ $error_value != 0 ]
221 then
222 print_error_msg
223 fi
224 ;;
225 *)
226 startup $i start
227 error_value=$?
228#
229# If the return value of the script is not 0, something went wrong with
230# error checking inside the script. the print_error_msg function will be
231# called and the message plus the return value of the K script will be
232# printed to the screen
233#
234
235 if [ $error_value != 0 ]
236 then
237 print_error_msg
238 fi
239 ;;
240 esac
241 done
242fi
243
244# End /etc/init.d/rc
245<userinput>EOF</userinput></screen></para>
246
247</sect1>
248
Note: See TracBrowser for help on using the repository browser.