/[baselayout]/branches/rc-scripts-1_6/sbin/rc
Gentoo

Contents of /branches/rc-scripts-1_6/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 792 - (show annotations) (download)
Wed Dec 15 19:59:49 2004 UTC (9 years, 10 months ago) by vapier
File size: 21294 byte(s)
rc

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