]>
git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - src/initscripts/core/rc
5faf1a00f6c5c8dc2ad3f227cd142e7497b72c53
2 # Begin $RC_BASE/init.d/rc
4 # Get the configuration file
5 # All changes are to occur in the config file
8 # These 3 signals will not cause our script to exit
11 # Simple sanity check - rc only takes one argument
12 if [ "${#}" -ne 1 ]; then
13 echo "Usage: ${0} <runlevel>" >&2
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
21 prevlevel
="${PREVLEVEL}"
23 # Just in case - some flavors of init don't set PREVLEVEL to 'N'
24 if [ "${prevlevel}" = "" ]; then
28 # Mount a tmpfs to store boot accounting information
29 if [ "${runlevel}" = "S" -a "${TEMPFS_MOUNT}" != "" ]; then
30 mount
-n -t tmpfs tmpfs
"${TEMPFS_MOUNT}" -o mode
=600
33 # Provide an interactive prompt (if requested)
34 if [ "${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
39 echo -e -n "${WARNING}WARNING: Either bash or zsh is required"
40 echo -e "${WARNING} for interactive startup.\n"
44 # dcol and icol are spaces before the message to center the
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}"
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" > "${TEMPFS_MOUNT}/.interactive-start"
61 # Verify that the directory exists
62 if [ ! -d "${RC_BASE}/rc${runlevel}.d" ]; then
63 echo -n -e "${WARNING}${RC_BASE}/rc${runlevel}.d does not exist."
68 # Source the interactive state file if it exists
69 if [ "${runlevel}" != "S" -a -f "${TEMPFS_MOUNT}/.interactive-start" ]; then
70 .
"${TEMPFS_MOUNT}/.interactive-start"
73 # Prompt for interactive startup after completing S
74 if [ "${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 "
81 if [ "${go_on}" = "n" ]; then
88 # Attempt to stop all services started in the previous runlevel,
89 # that are stopped in this runlevel
90 if [ "${prevlevel}" != "N" ]; then
91 for link
in $
(ls -v ${RC_BASE}/rc
${runlevel}.d
/K
* 2> /dev
/null
)
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
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
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
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})."
122 if [ "${error_value}" != "0" ]; then
128 # Start all functions in this runlevel if they weren't started in
129 # the previous runlevel
130 for link
in $
(ls -v ${RC_BASE}/rc
${runlevel}.d
/S
* 2> /dev
/null
)
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
137 [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
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
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
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
163 if [ "${startit}" = "y" -o "${startit}" = "Y" ]; then
166 echo -e -n "${WARNING}Not starting ${INFO}${link}"
167 echo -e "${WARNING}.${NORMAL}\n"
176 if [ "${error_value}" -gt "1" ]; then
181 # Strip apply time to the logs, strip out any color codes and dump
182 # the log to /var/log/boot.log
183 if [ -f "${TEMPFS_MOUNT}/.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' "${TEMPFS_MOUNT}/.bootlog"
186 #Fix the time and hostname
187 BTIMESPEC
=$
(echo `date -u +"%b %d %T"` `hostname`)
188 sed -i "s@^bootlog:@${BTIMESPEC} bootlog:@" "${TEMPFS_MOUNT}/.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 "${TEMPFS_MOUNT}/.bootlog" >> /var
/log
/boot.log
192 rm -f "${TEMPFS_MOUNT}/.bootlog"
196 # End $RC_BASE/init.d/rc