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

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

Parent Directory Parent Directory | Revision Log Revision Log


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