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

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 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 cross-chap5 ml-11.0 multilib old-trunk trunk xry111/git-transition xry111/glibc-2.34 xry111/tester-nohack xry111/usr-move
Last change on this file since b875e19 was b875e19, checked in by DJ Lucas <dj@…>, 5 years ago

Update to lfs-bootscripts-20170825. Fix a scope issue in the rc script. Thanks to quesker in #lfs-support for the report and subsequent testing.

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

  • Property mode set to 100644
File size: 6.2 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 SCRIPT_STAT="1"
41 fi
42
43 if [ ! -x ${i} ]; then
44 log_warning_msg "${i} is not executable, skipping."
45 SCRIPT_STAT="1"
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 if [ "${SCRIPT_STAT}" == "1" ]; then
154 SCRIPT_STAT="0"
155 continue
156 fi
157
158 suffix=${i#/etc/rc.d/rc$runlevel.d/K[0-9][0-9]}
159 prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
160 sysinit_start=/etc/rc.d/rcS.d/S[0-9][0-9]$suffix
161
162 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
163 if [ ! -f ${prev_start} -a ! -f ${sysinit_start} ]; then
164 MSG="WARNING:\n\n${i} can't be "
165 MSG="${MSG}executed because it was not "
166 MSG="${MSG}not started in the previous "
167 MSG="${MSG}runlevel (${previous})."
168 log_warning_msg "$MSG"
169 continue
170 fi
171 fi
172
173 run ${i} stop
174 error_value=${?}
175
176 if [ "${error_value}" != "0" ]; then print_error_msg; fi
177 done
178fi
179
180if [ "${previous}" == "N" ]; then export IN_BOOT=1; fi
181
182if [ "$runlevel" == "6" -a -n "${FASTBOOT}" ]; then
183 touch /fastboot
184fi
185
186
187# Start all functions in this runlevel
188for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null)
189do
190 if [ "${previous}" != "N" ]; then
191 suffix=${i#/etc/rc.d/rc$runlevel.d/S[0-9][0-9]}
192 stop=/etc/rc.d/rc$runlevel.d/K[0-9][0-9]$suffix
193 prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
194
195 [ -f ${prev_start} -a ! -f ${stop} ] && continue
196 fi
197
198 check_script_status
199 if [ "${SCRIPT_STAT}" == "1" ]; then
200 SCRIPT_STAT="0"
201 continue
202 fi
203
204 case ${runlevel} in
205 0|6)
206 run ${i} stop
207 ;;
208 *)
209 run ${i} start
210 ;;
211 esac
212
213 error_value=${?}
214
215 if [ "${error_value}" != "0" ]; then print_error_msg; fi
216done
217
218# Store interactive variable on switch from runlevel S and remove if not
219if [ "${runlevel}" == "S" -a "${interactive}" == "i" ]; then
220 echo "interactive=\"i\"" > /var/run/interactive
221else
222 rm -f /var/run/interactive 2> /dev/null
223fi
224
225# Copy the boot log on initial boot only
226if [ "${previous}" == "N" -a "${runlevel}" != "S" ]; then
227 cat $BOOTLOG >> /var/log/boot.log
228
229 # Mark the end of boot
230 echo "--------" >> /var/log/boot.log
231
232 # Remove the temporary file
233 rm -f $BOOTLOG 2> /dev/null
234fi
235
236# End rc
Note: See TracBrowser for help on using the repository browser.