/[baselayout]/trunk/sbin/rc
Gentoo

Contents of /trunk/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 795 - (show annotations) (download)
Thu Dec 16 01:36:17 2004 UTC (14 years, 5 months ago) by vapier
File size: 21830 byte(s)
RC_USE_FSTAB support

1 #!/bin/bash
2 # Copyright 1999-2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header$
5
6 trap ":" INT QUIT TSTP
7 source /sbin/functions.sh
8 # Only source this when this is a livecd booting ...
9 [ -f /sbin/livecd-functions.sh ] && source /sbin/livecd-functions.sh
10 umask 022
11
12 try() {
13 local errstr
14 local retval=0
15
16 if [ -c /dev/null ]; then
17 errstr="$((eval $*) 2>&1 >/dev/null)"
18 else
19 errstr="$((eval $*) 2>&1)"
20 fi
21 retval=$?
22 if [ "${retval}" -ne 0 ]
23 then
24 splash "critical" &
25
26 echo -e "${ENDCOL}${NORMAL}[${BAD} oops ${NORMAL}]"
27 echo
28 eerror "The \"${1}\" command failed with error:"
29 echo
30 echo "${errstr#*: }"
31 echo
32 eerror "Since this is a critical task, startup cannot continue."
33 echo
34 /sbin/sulogin ${CONSOLE}
35 einfo "Unmounting filesystems"
36 if [ -c /dev/null ]; then
37 /bin/mount -a -o remount,ro &>/dev/null
38 else
39 /bin/mount -a -o remount,ro
40 fi
41 einfo "Rebooting"
42 /sbin/reboot -f
43 fi
44
45 return ${retval}
46 }
47
48 # Check that $1 exists ...
49 check_statedir() {
50 [ -z "$1" ] && return 0
51
52 if [ ! -d "$1" ]
53 then
54 if ! mkdir -p "$1" &>/dev/null
55 then
56 splash "critical" &
57 echo
58 eerror "For Gentoo Linux to function properly, \"$1\" need to exist."
59 eerror "Please mount your root partition read/write, and execute:"
60 echo
61 eerror " # mkdir -p $1"
62 echo; echo
63 /sbin/sulogin ${CONSOLE}
64 einfo "Unmounting filesystems"
65 /bin/mount -a -o remount,ro &>/dev/null
66 einfo "Rebooting"
67 /sbin/reboot -f
68 fi
69 fi
70
71 return 0
72 }
73
74 udev_version() {
75 local version=0
76
77 if [ -x "/sbin/udev" ]
78 then
79 version=$(/sbin/udev -V)
80 # We need it without a leading '0', else bash do the wrong thing
81 version="${version##0}"
82 # Older udev's will print nothing
83 [ -z "${version}" ] && version=0
84 fi
85
86 echo "${version}"
87 }
88
89 populate_udev() {
90 # Make sure we do not have udevd from initramfs running
91 killall -q udevd
92 # Now populate /dev
93 /sbin/udevstart
94
95 # Not provided by sysfs but needed
96 ln -snf /proc/self/fd /dev/fd
97 ln -snf fd/0 /dev/stdin
98 ln -snf fd/1 /dev/stdout
99 ln -snf fd/2 /dev/stderr
100 ln -snf /proc/kcore /dev/core
101
102 # Create nodes that udev can't
103 [ -x /sbin/dmsetup ] && /sbin/dmsetup mknodes &>/dev/null
104 [ -x /sbin/lvm ] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
105
106 # Create problematic directories
107 mkdir -p /dev/{pts,shm}
108
109 # Same thing as /dev/.devfsd
110 touch /dev/.udev
111
112 return 0
113 }
114
115 get_critical_services() {
116 local x=
117 CRITICAL_SERVICES=
118
119 if [ -f "/etc/runlevels/${BOOTLEVEL}/.critical" ]
120 then
121 for x in $(< /etc/runlevels/${BOOTLEVEL}/.critical)
122 do
123 CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}"
124 done
125 else
126 CRITICAL_SERVICES="checkroot hostname modules checkfs localmount clock"
127 fi
128
129 export CRITICAL_SERVICES
130
131 return 0
132 }
133
134 # Save $1
135 argv1="$1"
136
137 # First time boot stuff goes here. Note that 'sysinit' is an internal runlevel
138 # used to bring up local filesystems, and should not be started with /sbin/rc
139 # directly ...
140 if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "sysinit" ]
141 then
142 # Setup initial $PATH just in case
143 PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}"
144
145 # Help users recover their systems incase these go missing
146 [ -c /dev/null ] && dev_null=1 || dev_null=0
147 [ -c /dev/console ] && dev_console=1 || dev_console=0
148
149 echo
150 echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}"
151 echo -e " Copyright 1999-2004 Gentoo Foundation; Distributed under the GPLv2"
152 echo
153
154 check_statedir /proc
155
156 ebegin "Mounting proc at /proc"
157 if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
158 mntcmd=$(get_mount_fstab /proc)
159 else
160 unset mntcmd
161 fi
162 try mount -n ${mntcmd:--t proc none /proc}
163 eend $?
164
165 # Read off the kernel commandline to see if there's any special settings
166 # especially check to see if we need to set the CDBOOT environment variable
167 # Note: /proc MUST be mounted
168 [ -f /sbin/livecd-functions.sh ] && livecd_read_commandline
169
170 if [ "$(get_KV)" -ge "$(KV_to_int '2.6.0')" ] ; then
171 if [[ -d /sys ]] ; then
172 ebegin "Mounting sysfs at /sys"
173 if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
174 mntcmd=$(get_mount_fstab /sys)
175 else
176 unset mntcmd
177 fi
178 try mount -n ${mntcmd:--t sysfs none /sys}
179 eend $?
180 else
181 ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
182 fi
183 fi
184
185 check_statedir /dev
186
187 # Fix weird bug where there is a /dev/.devfsd in a unmounted /dev
188 devfs_automounted="no"
189 if [ -e "/dev/.devfsd" ]
190 then
191 mymounts="$(awk '($3 == "devfs") { print "yes"; exit 0 }' /proc/mounts)"
192 if [ "${mymounts}" != "yes" ]
193 then
194 rm -f /dev/.devfsd
195 else
196 devfs_automounted="yes"
197 fi
198 fi
199
200 # Try to figure out how the user wants /dev handled
201 # - check $RC_DEVICES from /etc/conf.d/rc
202 # - check boot parameters
203 # - make sure the required binaries exist
204 # - make sure the kernel has support
205 if [ "${RC_DEVICES}" = "static" ]
206 then
207 ebegin "Using existing device nodes in /dev"
208 eend 0
209 else
210 fellback_to_devfs="no"
211 case "${RC_DEVICES}" in
212 devfs) devfs="yes"
213 udev="no"
214 ;;
215 udev) devfs="yes"
216 udev="yes"
217 fellback_to_devfs="yes"
218 ;;
219 auto|*) devfs="yes"
220 udev="yes"
221 ;;
222 esac
223
224 # Check udev prerequisites and kernel params
225 if [ "${udev}" = "yes" ]
226 then
227 if get_bootparam "noudev" || \
228 [ ! -x /sbin/udev -o -e "/dev/.devfsd" ] || \
229 [ "$(get_KV)" -lt "$(KV_to_int '2.6.0')" ]
230 then
231 udev="no"
232 fi
233 fi
234
235 # Check devfs prerequisites and kernel params
236 if [ "${devfs}" = "yes" ]
237 then
238 if get_bootparam "nodevfs" || [ "${udev}" = "yes" ]
239 then
240 devfs="no"
241 fi
242 fi
243
244 # Actually start setting up /dev now
245 if [[ ${udev} = "yes" ]] ; then
246 # Setup temporary storage for /dev
247 ebegin "Mounting /dev for udev"
248 if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
249 mntcmd=$(get_mount_fstab /dev)
250 else
251 unset mntcmd
252 fi
253 if [[ -n ${mntcmd} ]] ; then
254 try mount -n ${mntcmd}
255 else
256 if egrep -qs tmpfs /proc/filesystems ; then
257 try mount -n -t tmpfs none /dev
258 else
259 try mount -n -t ramfs none /dev
260 fi
261 fi
262 eend $?
263
264 # Actually get udev rolling
265 ebegin "Configuring system to use udev"
266 if [[ ${RC_DEVICE_TARBALL} = "yes" ]] && [[ -s /lib/udev-state/devices.tar.bz2 ]]
267 then
268 einfo " Populating /dev with device nodes ..."
269 try tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
270 fi
271 populate_udev
272
273 # Setup hotplugging (if possible)
274 if [ -e /proc/sys/kernel/hotplug ]
275 then
276 if [ "$(udev_version)" -ge "48" ]
277 then
278 einfo " Setting /sbin/udevsend as hotplug agent ..."
279 echo "/sbin/udevsend" > /proc/sys/kernel/hotplug
280 elif [ -x /sbin/hotplug ]
281 then
282 einfo " Using /sbin/hotplug as hotplug agent ..."
283 else
284 einfo " Setting /sbin/udev as hotplug agent ..."
285 echo "/sbin/udev" > /proc/sys/kernel/hotplug
286 fi
287 fi
288 eend 0
289
290 # With devfs, /dev can be mounted by the kernel ...
291 elif [ "${devfs}" = "yes" ]
292 then
293 mymounts="$(awk '($2 == "devfs") { print "yes"; exit 0 }' /proc/filesystems)"
294 # Is devfs support compiled in?
295 if [ "${mymounts}" = "yes" ]
296 then
297 if [ "${devfs_automounted}" = "no" ]
298 then
299 ebegin "Mounting devfs at /dev"
300 try mount -n -t devfs none /dev
301 eend $?
302 else
303 ebegin "Kernel automatically mounted devfs at /dev"
304 eend 0
305 fi
306 ebegin "Starting devfsd"
307 /sbin/devfsd /dev >/dev/null
308 eend $? "Could not start /sbin/devfsd"
309 else
310 devfs="no"
311 fi
312
313 # Did the user want udev in the config file but for
314 # some reason, udev support didnt work out ?
315 if [ "${fellback_to_devfs}" = "yes" ]
316 then
317 ewarn "You wanted udev but support for it was not available!"
318 ewarn "Please review your system after it's booted!"
319 fi
320 fi
321
322 # OK, if we got here, things are probably not right :)
323 if [ "${devfs}" = "no" ] && [ "${udev}" = "no" ]
324 then
325 clear
326 echo
327 einfo "The Gentoo Linux system initialization scripts have detected that"
328 einfo "your system does not support DEVFS or UDEV. Since Gentoo Linux"
329 einfo "has been designed with these dynamic /dev managers in mind, it is"
330 einfo "highly suggested that you build support for it into your kernel."
331 einfo "Please read the Gentoo Handbook for more information!"
332 echo
333 einfo " http://www.gentoo.org/doc/en/handbook/"
334 echo
335 einfo "Thanks for using Gentoo! :)"
336 echo
337 read -t 15 -p "(hit Enter to continue or wait 15 seconds ...)"
338 fi
339 fi
340
341 # From linux-2.5.68 we need to mount /dev/pts again ...
342 if [ "$(get_KV)" -ge "$(KV_to_int '2.5.68')" ]
343 then
344 have_devpts="$(awk '($2 == "devpts") { print "yes"; exit 0 }' /proc/filesystems)"
345
346 if [ "${have_devpts}" = "yes" ]
347 then
348 # Only try to create /dev/pts if we have /dev mounted dynamically,
349 # else it might fail as / might be still mounted readonly.
350 if [ ! -d /dev/pts ] && \
351 [ "${devfs}" = "yes" -o "${udev}" = "yes" ]
352 then
353 # Make sure we have /dev/pts
354 mkdir -p /dev/pts &>/dev/null || \
355 ewarn "Could not create /dev/pts!"
356 fi
357
358 if [[ -d /dev/pts ]] ; then
359 ebegin "Mounting devpts at /dev/pts"
360 if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
361 mntcmd=$(get_mount_fstab /dev/pts)
362 else
363 unset mntcmd
364 fi
365 try mount -n ${mntcmd:--t devpts -o gid=5,mode=0620 none /dev/pts}
366 eend $?
367 fi
368 fi
369 fi
370
371 if [ -x /sbin/irqbalance -a "$(get_KV)" -ge "$(KV_to_int '2.5.0')" ]
372 then
373 ebegin "Starting irqbalance"
374 /sbin/irqbalance
375 eend $?
376 fi
377
378 # Swap needs to be activated *after* devfs has been mounted and *after*
379 # devfsd has been started, so that the fstab can be properly parsed
380 # and only if the server/Gentoo box is initialized ...
381 ebegin "Activating (possible) swap"
382 /sbin/swapon -a &>/dev/null
383 eend 0
384
385 # Set the console loglevel to 1 for a cleaner boot
386 # the logger should anyhow dump the ring-0 buffer at start to the
387 # logs, and that with dmesg can be used to check for problems
388 /bin/dmesg -n 1
389
390 # We set the forced softlevel from the kernel command line
391 # It needs to be run right after proc is mounted for the
392 # boot runlevel
393 setup_defaultlevels
394
395 # $BOOT can be used by rc-scripts to test if it is the first time
396 # the 'boot' runlevel is executed. Now also needed by some stuff in
397 # the 'sysinit' runlevel ...
398 export BOOT="yes"
399
400 start_critical_service() {
401 (
402 local retval=
403 local service=$1
404
405 source "/etc/init.d/${service}" || eerror "Failed to source /etc/init.d/${service}"
406 retval=$?
407 [ "${retval}" -ne 0 ] && return "${retval}"
408 [ -e "/etc/conf.d/${service}" ] && source "/etc/conf.d/${service}"
409 source /etc/rc.conf
410
411 start || eerror "Failed to start /etc/init.d/${service}"
412 retval=$?
413
414 return "${retval}"
415 )
416 }
417
418 # We first try to find a locally defined list of critical services
419 # for a particular runlevel. If we cannot find it, we use the
420 # defaults.
421 get_critical_services
422
423 splash "rc_init" "${argv1}"
424
425 # We do not want to break compatibility, so we do not fully integrate
426 # these into /sbin/rc, but rather start them by hand ...
427 for x in ${CRITICAL_SERVICES}
428 do
429 splash "svc_start" "${x}"
430
431 if ! start_critical_service "${x}"
432 then
433 splash "critical" &>/dev/null &
434
435 echo
436 eerror "One of more critical startup scripts failed to start!"
437 eerror "Please correct this, and reboot ..."
438 echo; echo
439 /sbin/sulogin ${CONSOLE}
440 einfo "Unmounting filesystems"
441 /bin/mount -a -o remount,ro &>/dev/null
442 einfo "Rebooting"
443 /sbin/reboot -f
444 fi
445
446 splash "svc_started" "${x}" "0"
447 done
448
449 # Check that $svcdir exists ...
450 check_statedir "${svcdir}"
451
452 # Should we use tmpfs/ramfs/ramdisk for caching dependency and
453 # general initscript data? Note that the 'gentoo=<fs>' kernel
454 # option should override any other setting ...
455 for fs in tmpfs ramfs ramdisk
456 do
457 if get_bootparam "${fs}"
458 then
459 svcmount="yes"
460 svcfstype="${fs}"
461 break
462 fi
463 done
464 if [ "${svcmount}" = "yes" ]
465 then
466 ebegin "Mounting ${svcfstype} at ${svcdir}"
467 case "${svcfstype}" in
468 ramfs)
469 try mount -n -t ramfs ramfs "${svcdir}" \
470 -o rw,mode=0644,size="${svcsize}"k
471 ;;
472 ramdisk)
473 try dd if=/dev/zero of=/dev/ram0 bs=1k count="${svcsize}"
474 try /sbin/mke2fs -i 1024 -vm0 /dev/ram0 "${svcsize}"
475 try mount -n -t ext2 /dev/ram0 "${svcdir}" -o rw
476 ;;
477 tmpfs|*)
478 try mount -n -t tmpfs tmpfs "${svcdir}" \
479 -o rw,mode=0644,size="${svcsize}"k
480 ;;
481 esac
482 eend 0
483 fi
484
485 # If booting off CD, we want to update inittab before setting the runlevel
486 if [ -f "/sbin/livecd-functions.sh" -a -n "${CDBOOT}" ]
487 then
488 ebegin "Updating inittab"
489 livecd_fix_inittab
490 eend $?
491 /sbin/telinit q &>/dev/null
492 fi
493
494 # Clear $svcdir from stale entries, but leave the caches around, as it
495 # should help speed things up a bit
496 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
497 grep -ve '\(depcache\|deptree\|envcache\)')
498
499 # Update the dependency cache
500 /sbin/depscan.sh -u
501
502 # Now that the dependency cache are up to date, make sure these
503 # are marked as started ...
504 (
505 # Needed for mark_service_started()
506 source "${svclib}/sh/rc-services.sh"
507
508 for x in ${CRITICAL_SERVICES}
509 do
510 mark_service_started "${x}"
511 done
512 )
513
514 # If the user's /dev/null or /dev/console are missing, we
515 # should help them out and explain how to rectify the situation
516 if [ ${dev_null} -eq 0 -o ${dev_console} -eq 0 ] \
517 && [ -e /usr/share/baselayout/issue.devfix ]
518 then
519 # Backup current /etc/issue
520 if [ -e /etc/issue -a ! -e /etc/issue.devfix ]
521 then
522 mv /etc/issue /etc/issue.devfix
523 fi
524
525 cp /usr/share/baselayout/issue.devfix /etc/issue
526 fi
527
528 # Setup login records ... this has to be done here because when
529 # we exit this runlevel, init will write a boot record to utmp
530 # If /var/run is readonly, then print a warning, not errors
531 if touch /var/run/utmp 2>/dev/null
532 then
533 > /var/run/utmp
534 touch /var/log/wtmp
535 chgrp utmp /var/run/utmp /var/log/wtmp
536 chmod 0664 /var/run/utmp /var/log/wtmp
537 # Remove /var/run/utmpx (bug from the past)
538 rm -f /var/run/utmpx
539 else
540 ewarn "Skipping /var/run/utmp initialization (ro root?)"
541 fi
542
543 exit 0
544 fi # Sysinit ends here
545
546 if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "boot" ]
547 then
548 setup_defaultlevels
549
550 if [ -n "${DEFAULTLEVEL}" -a "${DEFAULTLEVEL}" != "default" ]
551 then
552 # Setup our default runlevel runlevel that will be run
553 # the first time /sbin/rc is called with argv1 != sysinit|boot
554 echo "${DEFAULTLEVEL}" > "${svcdir}/ksoftlevel"
555 fi
556
557 # $BOOT can be used by rc-scripts to test if it is the first time
558 # the 'boot' runlevel is executed
559 export BOOT="yes"
560
561 # We reset argv1 to the bootlevel given on the kernel command line
562 # if there is one
563 argv1="${BOOTLEVEL}"
564
565 elif [ "${RUNLEVEL}" != "S" -a -e "${svcdir}/ksoftlevel" ]
566 then
567 argv1="$(< ${svcdir}/ksoftlevel)"
568 rm -f "${svcdir}/ksoftlevel"
569 fi
570
571 source "${svclib}/sh/rc-services.sh"
572 source "${svclib}/sh/rc-daemon.sh"
573
574 if [ -f "${svcdir}/softlevel" ]
575 then
576 # Set OLDSOFTLEVEL if we had a valid SOFTLEVEL
577 export OLDSOFTLEVEL="$(< ${svcdir}/softlevel)"
578 else
579 export OLDSOFTLEVEL=
580 fi
581
582 if [ -z "${argv1}" ]
583 then
584 if [ -f "${svcdir}/softlevel" ]
585 then
586 export SOFTLEVEL="$(< ${svcdir}/softlevel)"
587 else
588 export SOFTLEVEL="${BOOTLEVEL}"
589 fi
590 else
591 export SOFTLEVEL="${argv1}"
592 fi
593
594 if [ ! -f "${svcdir}/softlevel" ]
595 then
596 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
597 fi
598
599 # For keeping a list of services that fails during boot/halt
600 if [ ! -d "${svcdir}/failed" ]
601 then
602 mkdir -p -m 0755 "${svcdir}/failed"
603 else
604 rm -rf "${svcdir}"/failed/*
605 fi
606
607 splash "rc_init" "${argv1}"
608
609 if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
610 then
611 myscripts=
612
613 elif [ "${SOFTLEVEL}" = "single" ]
614 then
615 get_critical_services
616
617 myscripts="${CRITICAL_SERVICES}"
618
619 elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ]
620 then
621 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting ..."
622 exit 1
623 else
624 myscripts=
625 if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
626 then
627 # Normal runlevels *include* boot scripts
628 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
629 mylevels="${mylevels} $(dolisting /etc/runlevels/${BOOTLEVEL}/)"
630 else
631 # Non-normal runlevels don't include boot scripts as default
632 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
633 fi
634
635 [ "${OLDSOFTLEVEL}" = "${BOOTLEVEL}" -o "${OLDSOFTLEVEL}" = "single" ] \
636 && /bin/dmesg -n 1
637
638 for x in ${mylevels}
639 do
640 [ -L "${x}" ] && myscripts="${myscripts} ${x##*/}"
641 done
642 fi
643
644 # The softscripts dir contains all scripts that belong to the
645 # runlevel specified in ${svcdir}/softlevel
646 # It needs to be a new directory, else when stopping the services
647 # and the old directory is not intact, things get broken
648
649 mkdir -p -m 0755 "${svcdir}/softscripts.new"
650
651 for x in ${myscripts}
652 do
653 if [ ! -e "/etc/init.d/${x}" ]
654 then
655 ewarn "WARNING: /etc/init.d/${x} missing; skipping ..."
656 continue
657 fi
658 # The -f eliminates a warning if the symlink already exists,
659 # which can happen if a service is in both the boot level and
660 # the current "normal" runlevel
661 ln -snf "/etc/init.d/${x}" "${svcdir}/softscripts.new/${x}"
662 done
663
664 dep_stop() {
665 local x=
666 local dep=
667 local needsme=
668 local myservice="${1##*/}"
669 local depservice=
670
671 if service_stopped "${myservice}"
672 then
673 return 0
674 fi
675
676 # Candidate for zapping
677 if [ ! -L "${svcdir}/softscripts.new/${myservice}" ]
678 then
679 # If this is a 'net' service, we do not want to stop it if it was
680 # not in the previous runlevel, and we are not shutting down,
681 # rebooting or going to single runlevel. This is because the user
682 # might have started it (net.ppp?), or possibly hotplug ...
683 if net_service "${myservice}" && \
684 [ "${SOFTLEVEL}" != "reboot" -a \
685 "${SOFTLEVEL}" != "shutdown" -a \
686 "${SOFTLEVEL}" != "single" ]
687 then
688 if [ -z "${OLDSOFTLEVEL}" ] || \
689 ! in_runlevel "${myservice}" "${OLDSOFTLEVEL}"
690 then
691 # This service is not in the previous runlevel, so
692 # do not stop it ...
693 return 0
694 fi
695 fi
696
697 # Should not work for 'use'
698 if [ -z "$(needsme "${myservice}")" ]
699 then
700 # Nothing depends on me
701 stop_service "${myservice}"
702 else
703 # Something may depend on me
704 needsme=0
705
706 for dep in $(needsme "${myservice}")
707 do
708 if service_started "${dep}" && \
709 [ -L "${svcdir}/softscripts.new/${dep}" ]
710 then
711 # This dep is valid
712 needsme=1
713
714 break
715 fi
716 done
717
718 if [ "${needsme}" -eq 0 ]
719 then
720 stop_service "${myservice}"
721 fi
722 fi
723 fi
724 }
725
726 # Stop services
727 if [ "${SOFTLEVEL}" != "single" -a \
728 "${SOFTLEVEL}" != "reboot" -a \
729 "${SOFTLEVEL}" != "shutdown" ]
730 then
731 for i in $(dolisting "${svcdir}/started/")
732 do
733 dep_stop "${i}"
734 done
735 else
736 get_critical_services
737
738 is_critical_service() {
739 local x=
740 local myservice="${1##*/}"
741
742 for x in ${CRITICAL_SERVICES}
743 do
744 if [ "${myservice}" = "${x}" ]
745 then
746 return 0
747 fi
748 done
749
750 return 1
751 }
752
753 # First stop non critical services
754 for i in $(dolisting "${svcdir}/started/")
755 do
756 if [ -n "${LOGGER_SERVICE}" ]
757 then
758 # Only stop it if the logger do not depends on it
759 if ! query_before "${i##*/}" "${LOGGER_SERVICE}"
760 then
761 continue
762 fi
763 fi
764
765 # Do not stop critical services just yet
766 is_critical_service "${i}" || dep_stop "${i}"
767 done
768
769 # Now stop the logger if running
770 if [ -n "${LOGGER_SERVICE}" ]
771 then
772 dep_stop "${LOGGER_SERVICE}"
773 fi
774
775 # Now stop the rest
776 for i in $(dolisting "${svcdir}/started/")
777 do
778 dep_stop "${i}"
779 done
780 fi
781
782 # Only change softlevel AFTER all the services have been stopped,
783 # else they will not get the depend's right (wrong SOFTLEVEL)
784
785 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
786
787 if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
788 then
789 source /sbin/functions.sh
790
791 # Clear $svcdir from stale entries, but leave the caches around, as it
792 # should help speed things up a bit
793 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
794 grep -ve '\(depcache\|deptree\|envcache\)')
795
796 source /etc/init.d/halt.sh
797
798 if [ "${SOFTLEVEL}" = "reboot" ]
799 then
800 source /etc/init.d/reboot.sh
801 else
802 source /etc/init.d/shutdown.sh
803 fi
804
805 # Should never get here
806 exit 0
807 fi
808
809 # Move the old softscritps directory to a different one
810 # and make the new softscripts directory the current
811
812 mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old"
813 mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts"
814
815 dep_start() {
816 local myservice="${1##*/}"
817
818 [ ! -L "${svcdir}/softscripts/${myservice}" ] && continue
819
820 # Only start a script if it isn't already running
821 service_started "${myservice}" || schedule_service_startup "${myservice}"
822 }
823
824 get_critical_services
825
826 EXTRA_SOFTSCRIPTS="${CRITICAL_SERVICES}"
827
828 if [ -n "${LOGGER_SERVICE}" -a -L "${svcdir}/softscripts/${LOGGER_SERVICE}" ]
829 then
830 service_started "${LOGGER_SERVICE}" || \
831 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${LOGGER_SERVICE}"
832 fi
833
834 if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
835 then
836 for i in $(dolisting "/etc/runlevels/${BOOTLEVEL}/")
837 do
838 [ -L "${svcdir}/softscripts/${i##*/}" ] && \
839 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${i##*/}"
840 done
841 fi
842
843 # Start scripts
844 for i in ${EXTRA_SOFTSCRIPTS} $(dolisting "${svcdir}/softscripts/")
845 do
846 dep_start "${i##*/}"
847 done
848
849 # Wait for any services that may still be running ...
850 [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
851
852 # Clean the old runlevel
853 rm -rf "${svcdir}/softscripts.old" &>/dev/null
854
855 # Depends gets nuked, so update them
856 # (this problem should be solved now, but i think it will be a good idea
857 # to recreate the deps after a change in runlevel)
858
859 #/sbin/depscan.sh &>/dev/null
860
861 # We want devfsd running after a change of runlevel (this is mostly if we return
862 # from runlevel 'single')
863 if [ -z "`ps --no-heading -C 'devfsd'`" -a \
864 -n "`gawk '/\/dev devfs/ { print }' /proc/mounts 2>/dev/null`" ]
865 then
866 if [ "${RC_DEVFSD_STARTUP}" != "no" ]
867 then
868 /sbin/devfsd /dev &>/dev/null
869 fi
870 fi
871
872 # Runlevel end, so clear stale fail list
873 rm -rf "${svcdir}/failed" &>/dev/null
874
875 # If we were in the boot runlevel, it is done now ...
876 [ -n "${BOOT}" ] && unset BOOT
877
878 splash "rc_exit"
879
880 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20