]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - src/initscripts/core/rc
Added some indication in what stage we are running.
[people/ms/ipfire-3.x.git] / src / initscripts / core / rc
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/sysconfig/rc
7
8 # These 3 signals will not cause our script to exit
9 trap "" INT QUIT TSTP
10
11 # Simple sanity check - rc only takes one argument
12 if [ "${#}" -ne 1 ]; then
13 echo "Usage: ${0} <runlevel>" >&2
14 exit 1
15 fi
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
20 runlevel="${1}"
21 prevlevel="${PREVLEVEL}"
22
23 # Just in case - some flavors of init don't set PREVLEVEL to 'N'
24 if [ "${prevlevel}" = "" ]; then
25 prevlevel="N"
26 fi
27
28 if [ "${runlevel}" = "S" ]; then
29 touch /dev/.in_sysinit
30 fi
31
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
35 fi
36
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
42 # We are using ash
43 echo -e -n "${WARNING}WARNING: Either bash or zsh is required"
44 echo -e "${WARNING} for interactive startup.\n"
45 sleep 3
46 else
47 echo ""
48 # dcol and icol are spaces before the message to center the
49 # message on screen.
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}"
54 echo ""
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"
60 fi
61 fi
62 fi
63
64
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."
68 echo -e "${NORMAL}"
69 exit 1
70 fi
71
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"
75 fi
76
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 "
83 read -n 1 go_on
84 echo ""
85 if [ "${go_on}" = "n" ]; then
86 # don't continue
87 exit 0
88 fi
89 fi
90
91
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)
96 do
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
101 fi
102
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
107 fi
108
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
112
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})."
119 echo -e "${NORMAL}"
120 continue
121 fi
122 fi
123 ${link} stop
124 error_value=${?}
125
126 if [ "${error_value}" != "0" ]; then
127 print_error_msg
128 fi
129 done
130 fi
131
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)
135 do
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
140
141 [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
142 fi
143
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
148 fi
149
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
154 fi
155
156 case ${runlevel} in
157 0|6)
158 ${link} stop
159 ;;
160
161 *)
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
166 echo ""
167 if [ "${startit}" = "y" -o "${startit}" = "Y" ]; then
168 ${link} start
169 else
170 echo -e -n "${WARNING}Not starting ${INFO}${link}"
171 echo -e "${WARNING}.${NORMAL}\n"
172 fi
173 else
174 ${link} start
175 fi
176 ;;
177 esac
178 error_value=${?}
179
180 if [ "${error_value}" -gt "1" ]; then
181 print_error_msg
182 fi
183 done
184
185 rm -f /dev/.in_sysinit
186
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"
199 fi
200 fi
201
202 # End $RC_BASE/init.d/rc