source: lsb-bootscripts/etc/init.d/rc@ 63a2c2d

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 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 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 63a2c2d was 63a2c2d, checked in by DJ Lucas <dj@…>, 13 years ago

Moved BOOK/bootscripts/contrib/lsb-v3 to BOOK/lsb-bootscripts.

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

  • Property mode set to 100644
File size: 6.3 KB
Line 
1#!/bin/sh
2# Begin $RC_BASE/init.d/rc
3
4# Get the configuration file
5# All changes are to occur in the config file
6. /etc/default/rc
7
8# These 3 signals will not cause our script to exit
9trap "" INT QUIT TSTP
10
11# Simple sanity check - rc only takes one argument
12if [ "${#}" -ne 1 ]; then
13 echo "Usage: ${0} <runlevel>" >&2
14 exit 1
15fi
16
17# Do not use the RUNLEVEL and PREVLEVEL variables provided by init so
18# that they can be modified and alternate directories (S) can
19# be used without affecting init
20runlevel="${1}"
21prevlevel="${PREVLEVEL}"
22
23# Just in case - some flavors of init don't set PREVLEVEL to 'N'
24if [ "${prevlevel}" = "" ]; then
25 prevlevel="N"
26fi
27
28# Mount /run
29if [ "${runlevel}" = "S" ]; then
30 mount -n -t tmpfs tmpfs /run
31fi
32
33# Provide an interactive prompt (if requested)
34if [ "${runlevel}" = "S" -a "${iprompt}" = "yes" ]; then
35 # ash does not accept t and n flags for read
36 ls -l /bin/sh | grep "/ash"
37 if [ "${?}" -eq "0" ]; then
38 # We are using ash
39 echo -e -n "${WARNING}WARNING: Either bash or zsh is required"
40 echo -e "${WARNING} for interactive startup.\n"
41 sleep 3
42 else
43 echo ""
44 # dcol and icol are spaces before the message to center the
45 # message on screen.
46 dcol=$(( $(( ${COLUMNS} - ${dlen} )) / 2 ))
47 icol=$(( $(( ${COLUMNS} - ${ilen} )) / 2 ))
48 echo -e "\\033[${dcol}G${welcome_message}"
49 echo -e "\\033[${icol}G${i_message}${NORMAL}"
50 echo ""
51 read -t "${itime}" -n 1 interactive 2>&1 > /dev/null
52 if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
53 echo -n -e "${CURS_UP}"
54 echo -e "${INFO}Interactive boot selected...${NORMAL}"
55 echo "interactive=I" > /run/.interactive-start
56 fi
57 fi
58fi
59
60
61# Verify that the directory exists
62if [ ! -d "${RC_BASE}/rc${runlevel}.d" ]; then
63 echo -n -e "${WARNING}${RC_BASE}/rc${runlevel}.d does not exist."
64 echo -e "${NORMAL}"
65 exit 1
66fi
67
68# Source the interactive state file if it exists
69if [ "${runlevel}" != "S" -a -f /run/.interactive-start ]; then
70 . /run/.interactive-start
71fi
72
73# Prompt for interactive startup after completing S
74if [ "${interactive}" = "I" -a "${runlevel}" != "S" -a \
75 "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
76 echo -n -e "Proceed with interactive starup of runlevel "
77 echo -n -e "${INFO}${runlevel}${NORMAL}?"
78 echo -n -e "(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
79 read -n 1 go_on
80 echo ""
81 if [ "${go_on}" = "n" ]; then
82 # don't continue
83 exit 0
84 fi
85fi
86
87
88# Attempt to stop all services started in the previous runlevel,
89# that are stopped in this runlevel
90if [ "${prevlevel}" != "N" ]; then
91 for link in $(ls -v ${RC_BASE}/rc${runlevel}.d/K* 2> /dev/null)
92 do
93 # Check to see if link is a valid symlink
94 if [ ! -f ${link} ]; then
95 echo -e "${WARNING}${link} is not a valid symlink."
96 continue # go on to the next K* link
97 fi
98
99 # Check to see if link is executable
100 if [ ! -x ${link} ]; then
101 echo -e "${WARNING}${link} is not executable, skipping."
102 continue # go on to the next K* link
103 fi
104
105 script=${link#$RC_BASE/rc$runlevel.d/K[0-9][0-9]}
106 prev_start=$RC_BASE/rc$prevlevel.d/S[0-9][0-9]$script
107 S_start=$RC_BASE/rcS.d/S[0-9][0-9]$script
108
109 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
110 if [ ! -f ${prev_start} ] && [ ! -f ${S_start} ]; then
111 echo -e -n "${WARNING}WARNING:\n\n${link} can't be"
112 echo -e "${WARNING} executed because it was not"
113 echo -e -n "${WARNING} not started in the previous"
114 echo -e "${WARNING} runlevel (${prevlevel})."
115 echo -e "${NORMAL}"
116 continue
117 fi
118 fi
119 ${link} stop
120 error_value=${?}
121
122 if [ "${error_value}" -ne "0" ]; then
123 print_error_msg
124 fi
125 done
126fi
127
128# Start all functions in this runlevel if they weren't started in
129# the previous runlevel
130for link in $(ls -v ${RC_BASE}/rc${runlevel}.d/S* 2> /dev/null)
131do
132 if [ "${prevlevel}" != "N" ]; then
133 script=${link#$RC_BASE/rc$runlevel.d/S[0-9][0-9]}
134 stop=$RC_BASE/rc$runlevel.d/K[0-9][0-9]$script
135 prev_start=$RC_BASE/rc$prevlevel.d/S[0-9][0-9]$script
136
137 [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
138 fi
139
140 # Check to see if link is a valid symlink
141 if [ ! -f ${link} ]; then
142 echo -e "${WARNING}${link} is not a valid symlink."
143 continue # go on to the next K* link
144 fi
145
146 # Check to see if link is executable
147 if [ ! -x ${link} ]; then
148 echo -e "${WARNING}${link} is not executable, skipping."
149 continue # go on to the next K* link
150 fi
151
152 case ${runlevel} in
153 0|6)
154 ${link} stop
155 ;;
156
157 *)
158 if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
159 echo -e -n "${WARNING}Start ${INFO}${link} ${WARNING}?"
160 echo -e -n "${NORMAL}(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
161 read -n 1 startit 2>&1 > /dev/null
162 echo ""
163 if [ "${startit}" = "y" -o "${startit}" = "Y" ]; then
164 ${link} start
165 else
166 echo -e -n "${WARNING}Not starting ${INFO}${link}"
167 echo -e "${WARNING}.${NORMAL}\n"
168 fi
169 else
170 ${link} start
171 fi
172 ;;
173 esac
174 error_value=${?}
175
176 if [ "${error_value}" -gt "1" ]; then
177 print_error_msg
178 fi
179done
180
181# Strip apply time to the logs, strip out any color codes and dump
182# the log to /var/log/boot.log
183if [ -f /run/.bootlog -a "${runlevel}" != "S" ]; then
184 # Remove any color codes from the temp log file
185 sed -i 's@\\033\[[0-9];[0-9][0-9]m@@g' /run/.bootlog
186 #Fix the time and hostname
187 BTIMESPEC=$(echo `date +"%b %d %T"` `hostname`)
188 sed -i "s@^bootlog:@${BTIMESPEC} bootlog:@" /run/.bootlog
189 # Don't try and write in 0 and 6, this is a 'boot' log
190 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
191 cat /run/.bootlog >> /var/log/boot.log
192 rm -f /run/.bootlog
193 fi
194fi
195
196# Remove interactive boot temp file
197if [ -f /run/.interactive-start -a "${runlevel}" != "S" ]; then
198 rm -f /run/.interactive-start
199fi
200
201# End $RC_BASE/init.d/rc
Note: See TracBrowser for help on using the repository browser.