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