]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - src/initscripts/core/rc
5faf1a00f6c5c8dc2ad3f227cd142e7497b72c53
[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 # 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
31 fi
32
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
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" > "${TEMPFS_MOUNT}/.interactive-start"
56 fi
57 fi
58 fi
59
60
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."
64 echo -e "${NORMAL}"
65 exit 1
66 fi
67
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"
71 fi
72
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 "
79 read -n 1 go_on
80 echo ""
81 if [ "${go_on}" = "n" ]; then
82 # don't continue
83 exit 0
84 fi
85 fi
86
87
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)
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}" != "0" ]; then
123 print_error_msg
124 fi
125 done
126 fi
127
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)
131 do
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
179 done
180
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"
193 fi
194 fi
195
196 # End $RC_BASE/init.d/rc