source: bootscripts/lfs/init.d/rc@ e6b6261

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 7.10 7.10-rc1 7.7 7.7-rc1 7.8 7.8-rc1 7.9 7.9-rc1 7.9-rc2 8.0 8.0-rc1 8.1 8.1-rc1 8.1-rc2 8.2 8.2-rc1 8.3 8.3-rc1 8.3-rc2 8.4 8.4-rc1 9.0 9.0-rc1 9.1 9.1-rc1 BOOK.old cross-chap5 ml-11.0 multilib nosym old-trunk trunk xry111/git-transition xry111/glibc-2.34 xry111/tester-nohack xry111/usr-move
Last change on this file since e6b6261 was e6b6261, checked in by Bruce Dubbs <bdubbs@…>, 7 years ago

Update to linux-3.17.4
Update to kmod-19
Update to grep-2.21

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

  • Property mode set to 100644
File size: 6.0 KB
Line 
1#!/bin/bash
2########################################################################
3# Begin rc
4#
5# Description : Main Run Level Control Script
6#
7# Authors : Gerard Beekmans - gerard@linuxfromscratch.org
8# : DJ Lucas - dj@linuxfromscratch.org
9# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
10#
11# Version : LFS 7.0
12#
13########################################################################
14
15. /lib/lsb/init-functions
16
17print_error_msg()
18{
19 log_failure_msg
20 # $i is set when called
21 MSG="FAILURE:\n\nYou should not be reading this error message.\n\n"
22 MSG="${MSG}It means that an unforeseen error took place in\n"
23 MSG="${MSG}${i},\n"
24 MSG="${MSG}which exited with a return value of ${error_value}.\n"
25
26 MSG="${MSG}If you're able to track this error down to a bug in one of\n"
27 MSG="${MSG}the files provided by the ${DISTRO_MINI} book,\n"
28 MSG="${MSG}please be so kind to inform us at ${DISTRO_CONTACT}.\n"
29 log_failure_msg "${MSG}"
30
31 log_info_msg "Press Enter to continue..."
32 wait_for_user
33}
34
35check_script_status()
36{
37 # $i is set when called
38 if [ ! -f ${i} ]; then
39 log_warning_msg "${i} is not a valid symlink."
40 continue
41 fi
42
43 if [ ! -x ${i} ]; then
44 log_warning_msg "${i} is not executable, skipping."
45 continue
46 fi
47}
48
49run()
50{
51 if [ -z $interactive ]; then
52 ${1} ${2}
53 return $?
54 fi
55
56 while true; do
57 read -p "Run ${1} ${2} (Yes/no/continue)? " -n 1 runit
58 echo
59
60 case ${runit} in
61 c | C)
62 interactive=""
63 ${i} ${2}
64 ret=${?}
65 break;
66 ;;
67
68 n | N)
69 return 0
70 ;;
71
72 y | Y)
73 ${i} ${2}
74 ret=${?}
75 break
76 ;;
77 esac
78 done
79
80 return $ret
81}
82
83# Read any local settings/overrides
84[ -r /etc/sysconfig/rc.site ] && source /etc/sysconfig/rc.site
85
86DISTRO=${DISTRO:-"Linux From Scratch"}
87DISTRO_CONTACT=${DISTRO_CONTACT:-"lfs-dev@linuxfromscratch.org (Registration required)"}
88DISTRO_MINI=${DISTRO_MINI:-"LFS"}
89IPROMPT=${IPROMPT:-"no"}
90
91# These 3 signals will not cause our script to exit
92trap "" INT QUIT TSTP
93
94[ "${1}" != "" ] && runlevel=${1}
95
96if [ "${runlevel}" == "" ]; then
97 echo "Usage: ${0} <runlevel>" >&2
98 exit 1
99fi
100
101previous=${PREVLEVEL}
102[ "${previous}" == "" ] && previous=N
103
104if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then
105 log_info_msg "/etc/rc.d/rc${runlevel}.d does not exist.\n"
106 exit 1
107fi
108
109if [ "$runlevel" == "6" -o "$runlevel" == "0" ]; then IPROMPT="no"; fi
110
111# Note: In ${LOGLEVEL:-7}, it is ':' 'dash' '7', not minus 7
112if [ "$runlevel" == "S" ]; then
113 [ -r /etc/sysconfig/console ] && source /etc/sysconfig/console
114 dmesg -n "${LOGLEVEL:-7}"
115fi
116
117if [ "${IPROMPT}" == "yes" -a "${runlevel}" == "S" ]; then
118 # The total length of the distro welcome string, without escape codes
119 wlen=${wlen:-$(echo "Welcome to ${DISTRO}" | wc -c )}
120 welcome_message=${welcome_message:-"Welcome to ${INFO}${DISTRO}${NORMAL}"}
121
122 # The total length of the interactive string, without escape codes
123 ilen=${ilen:-$(echo "Press 'I' to enter interactive startup" | wc -c )}
124 i_message=${i_message:-"Press '${FAILURE}I${NORMAL}' to enter interactive startup"}
125
126
127 # dcol and icol are spaces before the message to center the message
128 # on screen. itime is the amount of wait time for the user to press a key
129 wcol=$(( ( ${COLUMNS} - ${wlen} ) / 2 ))
130 icol=$(( ( ${COLUMNS} - ${ilen} ) / 2 ))
131 itime=${itime:-"3"}
132
133 echo -e "\n\n"
134 echo -e "\\033[${wcol}G${welcome_message}"
135 echo -e "\\033[${icol}G${i_message}${NORMAL}"
136 echo ""
137 read -t "${itime}" -n 1 interactive 2>&1 > /dev/null
138fi
139
140# Make lower case
141[ "${interactive}" == "I" ] && interactive="i"
142[ "${interactive}" != "i" ] && interactive=""
143
144# Read the state file if it exists from runlevel S
145[ -r /var/run/interactive ] && source /var/run/interactive
146
147# Attempt to stop all services started by the previous runlevel,
148# and killed in this runlevel
149if [ "${previous}" != "N" ]; then
150 for i in $(ls -v /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null)
151 do
152 check_script_status
153
154 suffix=${i#/etc/rc.d/rc$runlevel.d/K[0-9][0-9]}
155 prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
156 sysinit_start=/etc/rc.d/rcS.d/S[0-9][0-9]$suffix
157
158 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
159 if [ ! -f ${prev_start} -a ! -f ${sysinit_start} ]; then
160 MSG="WARNING:\n\n${i} can't be "
161 MSG="${MSG}executed because it was not "
162 MSG="${MSG}not started in the previous "
163 MSG="${MSG}runlevel (${previous})."
164 log_warning_msg "$MSG"
165 continue
166 fi
167 fi
168
169 run ${i} stop
170 error_value=${?}
171
172 if [ "${error_value}" != "0" ]; then print_error_msg; fi
173 done
174fi
175
176if [ "${previous}" == "N" ]; then export IN_BOOT=1; fi
177
178if [ "$runlevel" == "6" -a -n "${FASTBOOT}" ]; then
179 touch /fastboot
180fi
181
182
183# Start all functions in this runlevel
184for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null)
185do
186 if [ "${previous}" != "N" ]; then
187 suffix=${i#/etc/rc.d/rc$runlevel.d/S[0-9][0-9]}
188 stop=/etc/rc.d/rc$runlevel.d/K[0-9][0-9]$suffix
189 prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
190
191 [ -f ${prev_start} -a ! -f ${stop} ] && continue
192 fi
193
194 check_script_status
195
196 case ${runlevel} in
197 0|6)
198 run ${i} stop
199 ;;
200 *)
201 run ${i} start
202 ;;
203 esac
204
205 error_value=${?}
206
207 if [ "${error_value}" != "0" ]; then print_error_msg; fi
208done
209
210# Store interactive variable on switch from runlevel S and remove if not
211if [ "${runlevel}" == "S" -a "${interactive}" == "i" ]; then
212 echo "interactive=\"i\"" > /var/run/interactive
213else
214 rm -f /var/run/interactive 2> /dev/null
215fi
216
217# Copy the boot log on initial boot only
218if [ "${previous}" == "N" -a "${runlevel}" != "S" ]; then
219 cat $BOOTLOG >> /var/log/boot.log
220
221 # Mark the end of boot
222 echo "--------" >> /var/log/boot.log
223
224 # Remove the temporary file
225 rm -f $BOOTLOG 2> /dev/null
226fi
227
228# End rc
Note: See TracBrowser for help on using the repository browser.