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