/[vps]/baselayout-vserver/branches/baselayout-1_12/sbin/rc
Gentoo

Contents of /baselayout-vserver/branches/baselayout-1_12/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 207 - (show annotations) (download)
Sun Jan 15 10:30:55 2006 UTC (8 years, 7 months ago) by phreak
File size: 10764 byte(s)
Removing {RC,svc}_interactive from etc/conf.d/rc and sbin/rc
1 #!/sbin/runscript
2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 trap ":" INT QUIT TSTP
6 source /sbin/functions.sh
7 umask 022
8
9 # Check that $1 exists ...
10 check_statedir() {
11 [ -z "$1" ] && return 0
12 if [ ! -d "$1" ] ; then
13 if ! mkdir -p "$1" &>/dev/null ; then
14 echo
15 eerror "For Gentoo to function properly, \"$1\" needs to exist."
16 /sbin/halt -f
17 fi
18 fi
19
20 return 0
21 }
22
23 get_critical_services() {
24 local x=
25 CRITICAL_SERVICES=
26
27 if [ -f "/etc/runlevels/${BOOTLEVEL}/.critical" ]
28 then
29 for x in $(< /etc/runlevels/${BOOTLEVEL}/.critical)
30 do
31 CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}"
32 done
33 else
34 CRITICAL_SERVICES="hostname"
35 fi
36
37 export CRITICAL_SERVICES
38
39 return 0
40 }
41
42 # Save $1
43 argv1="$1"
44
45 # First time boot stuff goes here. Note that 'sysinit' is an internal runlevel
46 # used to bring up local filesystems, and should not be started with /sbin/rc
47 # directly ...
48 if [[ ${argv1} = "sysinit" ]]
49 then
50 # Setup initial $PATH just in case
51 PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}"
52
53 echo
54 echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}"
55 echo -e " Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2"
56 echo
57
58 check_statedir /proc
59 check_statedir /dev
60
61 # OpenVZ needs to mount proc from inside
62 if [[ ! -e /proc/self ]]; then
63 mount -t proc none /proc
64 fi
65
66 # OpenVZ also needs devpts for vzctl enter
67 if [[ ! -e /dev/pts/0 ]]; then
68 have_devpts="$(awk '($2 == "devpts") { print "yes"; exit 0 }' /proc/filesystems)"
69
70 if [ "${have_devpts}" = "yes" ]; then
71 # Make sure we have /dev/pts
72 mkdir -p /dev/pts &>/dev/null || \
73 ewarn "Could not create /dev/pts!"
74
75 if [[ -d /dev/pts ]]; then
76 ebegin "Mounting devpts at /dev/pts"
77 mount -n -t devpts -o gid=5,mode=0620 devpts /dev/pts
78 eend $?
79 fi
80 fi
81 fi
82
83 # We set the forced softlevel from the kernel command line
84 # It needs to be run right after proc is mounted for the
85 # boot runlevel
86 setup_defaultlevels
87
88 # $BOOT can be used by rc-scripts to test if it is the first time
89 # the 'boot' runlevel is executed. Now also needed by some stuff in
90 # the 'sysinit' runlevel ...
91 export BOOT="yes"
92
93 start_critical_service() {
94 (
95 local retval=
96 local service="$1"
97 # Needed for some addons like dm-crypt that starts in critical services
98 local myservice="$1"
99
100 source "/etc/init.d/${service}"
101 retval=$?
102 if [[ ${retval} -ne 0 ]] ; then
103 eerror "Failed to source /etc/init.d/${service}"
104 return "${retval}"
105 fi
106
107 local conf="$(add_suffix /etc/conf.d/${service})"
108 [[ -e ${conf} ]] && source "${conf}"
109 conf="$(add_suffix /etc/rc.conf)"
110 [[ -e ${conf} ]] && source "${conf}"
111
112 start
113 retval=$?
114 [[ ${retval} -ne 0 ]] && eerror "Failed to start /etc/init.d/${service}"
115
116 return "${retval}"
117 )
118 }
119
120 # We first try to find a locally defined list of critical services
121 # for a particular runlevel. If we cannot find it, we use the
122 # defaults.
123 get_critical_services
124
125 # We do not want to break compatibility, so we do not fully integrate
126 # these into /sbin/rc, but rather start them by hand ...
127 for x in ${CRITICAL_SERVICES}
128 do
129 if ! start_critical_service "${x}" ; then
130 echo
131 eerror "One or more critical startup scripts failed to start!"
132 eerror "Please correct this, and reboot ..."
133 echo; echo
134 einfo "Rebooting"
135 /sbin/halt -f
136 fi
137 done
138
139 # Check that $svcdir exists ...
140 check_statedir "${svcdir}"
141
142
143 # Clear $svcdir from stale entries, but leave the caches around, as it
144 # should help speed things up a bit
145 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
146 grep -ve '\(depcache\|deptree\|envcache\)')
147
148 echo "sysinit" > "${svcdir}/softlevel"
149
150 # Update the dependency cache
151 /sbin/depscan.sh -u
152
153 # Now that the dependency cache are up to date, make sure these
154 # are marked as started ...
155 (
156 # Needed for mark_service_started()
157 source "${svclib}/sh/rc-services.sh"
158
159 for x in ${CRITICAL_SERVICES}
160 do
161 mark_service_started "${x}"
162 done
163 )
164
165 # Setup login records ... this has to be done here because when
166 # we exit this runlevel, init will write a boot record to utmp
167 # If /var/run is readonly, then print a warning, not errors
168 if touch /var/run/utmp 2>/dev/null
169 then
170 > /var/run/utmp
171 touch /var/log/wtmp
172 chgrp utmp /var/run/utmp /var/log/wtmp
173 chmod 0664 /var/run/utmp /var/log/wtmp
174 # Remove /var/run/utmpx (bug from the past)
175 rm -f /var/run/utmpx
176 else
177 ewarn "Skipping /var/run/utmp initialization (ro root?)"
178 fi
179
180 exit 0
181 fi # Sysinit ends here
182
183 if [[ ${argv1} == "boot" ]]
184 then
185 setup_defaultlevels
186
187 # $BOOT can be used by rc-scripts to test if it is the first time
188 # the 'boot' runlevel is executed
189 export BOOT="yes"
190
191 # We reset argv1 to the bootlevel given on the kernel command line
192 # if there is one
193 argv1="${BOOTLEVEL}"
194 fi
195
196 source "${svclib}/sh/rc-services.sh"
197
198 if [ -f "${svcdir}/softlevel" ]
199 then
200 # Set OLDSOFTLEVEL if we had a valid SOFTLEVEL
201 export OLDSOFTLEVEL="$(< ${svcdir}/softlevel)"
202 else
203 export OLDSOFTLEVEL=
204 fi
205
206 if [ -z "${argv1}" ]
207 then
208 if [ -f "${svcdir}/softlevel" ]
209 then
210 export SOFTLEVEL="$(< ${svcdir}/softlevel)"
211 else
212 export SOFTLEVEL="${BOOTLEVEL}"
213 fi
214 else
215 export SOFTLEVEL="${argv1}"
216 fi
217
218 if [ ! -f "${svcdir}/softlevel" ]
219 then
220 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
221 fi
222
223 # For keeping a list of services that fails during boot/halt
224 if [ ! -d "${svcdir}/failed" ]
225 then
226 mkdir -p -m 0755 "${svcdir}/failed"
227 else
228 rm -rf "${svcdir}"/failed/*
229 fi
230
231 if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
232 then
233 myscripts=
234
235 elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ]
236 then
237 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting ..."
238 exit 1
239 else
240 myscripts=
241 if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
242 then
243 # Normal runlevels *include* boot scripts
244 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
245 mylevels="${mylevels} $(dolisting /etc/runlevels/${BOOTLEVEL}/)"
246 else
247 # Non-normal runlevels don't include boot scripts as default
248 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
249 fi
250
251 for x in ${mylevels}
252 do
253 [ -L "${x}" ] && myscripts="${myscripts} ${x##*/}"
254 done
255 fi
256
257 # The softscripts dir contains all scripts that belong to the
258 # runlevel specified in ${svcdir}/softlevel
259 # It needs to be a new directory, else when stopping the services
260 # and the old directory is not intact, things get broken
261
262 mkdir -p -m 0755 "${svcdir}/softscripts.new"
263
264 for x in ${myscripts} ; do
265 if [[ ! -e /etc/init.d/${x} ]] ; then
266 ewarn "WARNING: /etc/init.d/${x} missing; skipping ..."
267 continue
268 fi
269 # The -f eliminates a warning if the symlink already exists,
270 # which can happen if a service is in both the boot level and
271 # the current "normal" runlevel
272 ln -snf "/etc/init.d/${x}" "${svcdir}/softscripts.new/${x}"
273 done
274
275 get_stop_services() {
276 local x list
277
278 for x in $(dolisting "${svcdir}/inactive/") \
279 $(dolisting "${svcdir}/started/") ; do
280 list="${list} ${x##*/}"
281 done
282
283 reverse_list $(trace_dependencies ${list})
284 }
285
286 dep_stop() {
287 local x dep needsme depservice
288 local myservice=${1##*/}
289
290 service_stopped "${myservice}" && return 0
291
292 # Candidate for zapping ?
293 [[ ! -L ${svcdir}/softscripts.new/${myservice} ]] || \
294 return 0
295
296 # If this is a 'net' service, we do not want to stop it if it was
297 # not in the previous runlevel, and we are not shutting down,
298 # rebooting or going to single runlevel. This is because the user
299 # (or hotplut) might have started it (net.ppp?) ...
300 if net_service "${myservice}" && \
301 [[ ${SOFTLEVEL} != "reboot" && \
302 ${SOFTLEVEL} != "shutdown" ]] ; then
303 if [[ -z ${OLDSOFTLEVEL} ]] || \
304 ! in_runlevel "${myservice}" "${OLDSOFTLEVEL}"
305 then
306 # This service is not in the previous runlevel, so
307 # do not stop it ...
308 return 0
309 fi
310 fi
311
312 # Should not work for 'use'
313 if [[ -z $(needsme "${myservice}") ]] ; then
314 # Nothing depends on me
315 stop_service "${myservice}"
316 else
317 # Something may depend on me
318 needsme=0
319
320 for dep in $(needsme "${myservice}") ; do
321 if [[ -L "${svcdir}/softscripts.new/${dep}" ]] ; then
322 # This dep is valid
323 needsme=1
324
325 break
326 fi
327 done
328
329 [[ ${needsme} -eq 0 ]] && stop_service "${myservice}"
330 fi
331 }
332
333 # Stop services
334 if [[ ${SOFTLEVEL} != "reboot" && \
335 ${SOFTLEVEL} != "shutdown" ]]
336 then
337 for i in $(get_stop_services) ; do
338 dep_stop "${i}"
339 done
340
341 # Wait for any services that may still be stopping ...
342 [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
343 else
344 get_critical_services
345
346 is_critical_service() {
347 local x
348 local myservice=${1##*/}
349
350 for x in ${CRITICAL_SERVICES} ${LOGGER_SERVICE} ; do
351 [[ ${myservice} == "${x}" ]] && return 0
352 done
353
354 return 1
355 }
356
357 # First stop non critical services
358 for i in $(get_stop_services) ; do
359 is_critical_service "${i}" || dep_stop "${i}"
360 done
361
362 # Wait for any services that may still be stopping ...
363 [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
364
365 export STOP_CRITICAL="yes"
366 # Now stop the rest
367 for i in $(get_stop_services) ; do
368 dep_stop "${i}"
369 done
370 unset STOP_CRITICAL
371 fi
372
373 # Only change softlevel AFTER all the services have been stopped,
374 # else they will not get the depend's right (wrong SOFTLEVEL)
375
376 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
377
378 if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
379 source /sbin/functions.sh
380
381 # Clear $svcdir from stale entries, but leave the caches around, as it
382 # should help speed things up a bit
383 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
384 grep -ve '\(depcache\|deptree\|envcache\)')
385
386 source /etc/init.d/halt.sh
387
388 if [[ ${SOFTLEVEL} == "reboot" ]] ; then
389 source /etc/init.d/reboot.sh
390 else
391 source /etc/init.d/shutdown.sh
392 fi
393
394 # Should never get here
395 exit 0
396 fi
397
398 # Move the old softscritps directory to a different one
399 # and make the new softscripts directory the current
400
401 mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old"
402 mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts"
403
404 get_start_services() {
405 local x list
406
407 get_critical_services
408 list=${CRITICAL_SERVICES}
409
410 [[ -n ${LOGGER_SERVICE} && \
411 -L ${svcdir}/softscripts/${LOGGER_SERVICE} ]] && \
412 list="${list} ${LOGGER_SERVICE}"
413
414 for x in $(dolisting "${svcdir}/softscripts/") ; do
415 list="${list} ${x##*/}"
416 done
417
418 trace_dependencies ${list}
419 }
420
421 # Start scripts
422 for i in $(get_start_services) ; do
423 if service_stopped "${i}" ; then
424 start_service "${i}"
425 fi
426 done
427
428 # Wait for any services that may still be running ...
429 [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
430
431 # Clean the old runlevel
432 rm -rf "${svcdir}/softscripts.old" &>/dev/null
433
434 # Runlevel end, so clear stale fail list
435 rm -rf "${svcdir}/failed" &>/dev/null
436
437 # If we were in the boot runlevel, it is done now ...
438 [[ -n ${BOOT} ]] && unset BOOT
439
440 # Remove the cached CONSOLETYPE
441 unset CONSOLETYPE
442
443 # vim:ts=4

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20