]>
git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - src/initscripts/core/rc
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 if [ "${runlevel}" = "S" ]; then
29 touch /dev
/.in_sysinit
32 # Mount a tmpfs to store boot accounting information
33 if [ "${runlevel}" = "S" -a "${TEMPFS_MOUNT}" != "" ]; then
34 mount
-n -t tmpfs tmpfs
"${TEMPFS_MOUNT}" -o mode
=600
37 # Provide an interactive prompt (if requested)
38 if [ "${runlevel}" = "S" -a "${iprompt}" = "yes" ]; then
39 # ash does not accept t and n flags for read
40 ls -l /bin
/sh |
grep "/ash"
41 if [ "${?}" -eq "0" ]; then
43 echo -e -n "${WARNING}WARNING: Either bash or zsh is required"
44 echo -e "${WARNING} for interactive startup.\n"
48 # dcol and icol are spaces before the message to center the
50 dcol
=$
(( $
(( ${COLUMNS} - ${dlen} )) / 2 ))
51 icol
=$
(( $
(( ${COLUMNS} - ${ilen} )) / 2 ))
52 echo -e "\\033[${dcol}G${welcome_message}"
53 echo -e "\\033[${icol}G${i_message}${NORMAL}"
55 read -t "${itime}" -n 1 interactive
2>&1 > /dev
/null
56 if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
57 echo -n -e "${CURS_UP}"
58 echo -e "${INFO}Interactive boot selected...${NORMAL}"
59 echo "interactive=I" > "${TEMPFS_MOUNT}/.interactive-start"
65 # Verify that the directory exists
66 if [ ! -d "${RC_BASE}/rc${runlevel}.d" ]; then
67 echo -n -e "${WARNING}${RC_BASE}/rc${runlevel}.d does not exist."
72 # Source the interactive state file if it exists
73 if [ "${runlevel}" != "S" -a -f "${TEMPFS_MOUNT}/.interactive-start" ]; then
74 .
"${TEMPFS_MOUNT}/.interactive-start"
77 # Prompt for interactive startup after completing S
78 if [ "${interactive}" = "I" -a "${runlevel}" != "S" -a \
79 "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
80 echo -n -e "Proceed with interactive starup of runlevel "
81 echo -n -e "${INFO}${runlevel}${NORMAL}?"
82 echo -n -e "(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
85 if [ "${go_on}" = "n" ]; then
92 # Attempt to stop all services started in the previous runlevel,
93 # that are stopped in this runlevel
94 if [ "${prevlevel}" != "N" ]; then
95 for link
in $
(ls -v ${RC_BASE}/rc
${runlevel}.d
/K
* 2> /dev
/null
)
97 # Check to see if link is a valid symlink
98 if [ ! -f ${link} ]; then
99 echo -e "${WARNING}${link} is not a valid symlink."
100 continue # go on to the next K* link
103 # Check to see if link is executable
104 if [ ! -x ${link} ]; then
105 echo -e "${WARNING}${link} is not executable, skipping."
106 continue # go on to the next K* link
109 script=${link#$RC_BASE/rc$runlevel.d/K[0-9][0-9]}
110 prev_start
=$RC_BASE/rc
$prevlevel.d
/S
[0-9][0-9]$script
111 S_start
=$RC_BASE/rcS.d
/S
[0-9][0-9]$script
113 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
114 if [ ! -f ${prev_start} ] && [ ! -f ${S_start} ]; then
115 echo -e -n "${WARNING}WARNING:\n\n${link} can't be"
116 echo -e "${WARNING} executed because it was not"
117 echo -e -n "${WARNING} not started in the previous"
118 echo -e "${WARNING} runlevel (${prevlevel})."
126 if [ "${error_value}" != "0" ]; then
132 # Start all functions in this runlevel if they weren't started in
133 # the previous runlevel
134 for link
in $
(ls -v ${RC_BASE}/rc
${runlevel}.d
/S
* 2> /dev
/null
)
136 if [ "${prevlevel}" != "N" ]; then
137 script=${link#$RC_BASE/rc$runlevel.d/S[0-9][0-9]}
138 stop
=$RC_BASE/rc
$runlevel.d
/K
[0-9][0-9]$script
139 prev_start
=$RC_BASE/rc
$prevlevel.d
/S
[0-9][0-9]$script
141 [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
144 # Check to see if link is a valid symlink
145 if [ ! -f ${link} ]; then
146 echo -e "${WARNING}${link} is not a valid symlink."
147 continue # go on to the next K* link
150 # Check to see if link is executable
151 if [ ! -x ${link} ]; then
152 echo -e "${WARNING}${link} is not executable, skipping."
153 continue # go on to the next K* link
162 if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
163 echo -e -n "${WARNING}Start ${INFO}${link} ${WARNING}?"
164 echo -e -n "${NORMAL}(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
165 read -n 1 startit
2>&1 > /dev
/null
167 if [ "${startit}" = "y" -o "${startit}" = "Y" ]; then
170 echo -e -n "${WARNING}Not starting ${INFO}${link}"
171 echo -e "${WARNING}.${NORMAL}\n"
180 if [ "${error_value}" -gt "1" ]; then
185 rm -f /dev
/.in_sysinit
187 # Strip apply time to the logs, strip out any color codes and dump
188 # the log to /var/log/boot.log
189 if [ -f "${TEMPFS_MOUNT}/.bootlog" -a "${runlevel}" != "S" ]; then
190 # Remove any color codes from the temp log file
191 sed -i 's@\\033\[[0-9];[0-9][0-9]m@@g' "${TEMPFS_MOUNT}/.bootlog"
192 #Fix the time and hostname
193 BTIMESPEC
=$
(echo `date -u +"%b %d %T"` `hostname`)
194 sed -i "s@^bootlog:@${BTIMESPEC} bootlog:@" "${TEMPFS_MOUNT}/.bootlog"
195 # Don't try and write in 0 and 6, this is a 'boot' log
196 if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
197 cat "${TEMPFS_MOUNT}/.bootlog" >> /var
/log
/boot.log
198 rm -f "${TEMPFS_MOUNT}/.bootlog"
202 # End $RC_BASE/init.d/rc