/[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 776 - (show annotations) (download)
Fri Dec 10 15:27:45 2004 UTC (9 years, 9 months ago) by vapier
File size: 21201 byte(s)
RC_USE_FSTAB to disable get_mount_fstab by default

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" ]
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
391 source "/etc/init.d/${x}" || eerror "Failed to source /etc/init.d/${x}"
392 retval=$?
393 [ "${retval}" -ne 0 ] && return "${retval}"
394 [ -e "/etc/conf.d/${x}" ] && source "/etc/conf.d/${x}"
395 source /etc/rc.conf
396
397 start || eerror "Failed to start /etc/init.d/${x}"
398 retval=$?
399
400 return "${retval}"
401 )
402 }
403
404 # We first try to find a locally defined list of critical services
405 # for a particular runlevel. If we cannot find it, we use the
406 # defaults.
407 get_critical_services
408
409 splash "rc_init" "${argv1}"
410
411 # We do not want to break compatibility, so we do not fully integrate
412 # these into /sbin/rc, but rather start them by hand ...
413 for x in ${CRITICAL_SERVICES}
414 do
415 splash "svc_start" "${x}"
416
417 if ! start_critical_service "${x}"
418 then
419 splash "critical" &>/dev/null &
420
421 echo
422 eerror "One of more critical startup scripts failed to start!"
423 eerror "Please correct this, and reboot ..."
424 echo; echo
425 /sbin/sulogin ${CONSOLE}
426 einfo "Unmounting filesystems"
427 /bin/mount -a -o remount,ro &>/dev/null
428 einfo "Rebooting"
429 /sbin/reboot -f
430 fi
431
432 splash "svc_started" "${x}" "0"
433 done
434
435 # Check that $svcdir exists ...
436 check_statedir "${svcdir}"
437
438 # Should we use tmpfs/ramfs/ramdisk for caching dependency and
439 # general initscript data? Note that the 'gentoo=<fs>' kernel
440 # option should override any other setting ...
441 for fs in tmpfs ramfs ramdisk
442 do
443 if get_bootparam "${fs}"
444 then
445 svcmount="yes"
446 svcfstype="${fs}"
447 break
448 fi
449 done
450 if [ "${svcmount}" = "yes" ]
451 then
452 ebegin "Mounting ${svcfstype} at ${svcdir}"
453 case "${svcfstype}" in
454 ramfs)
455 try mount -n -t ramfs ramfs "${svcdir}" \
456 -o rw,mode=0644,size="${svcsize}"k
457 ;;
458 ramdisk)
459 try dd if=/dev/zero of=/dev/ram0 bs=1k count="${svcsize}"
460 try /sbin/mke2fs -i 1024 -vm0 /dev/ram0 "${svcsize}"
461 try mount -n -t ext2 /dev/ram0 "${svcdir}" -o rw
462 ;;
463 tmpfs|*)
464 try mount -n -t tmpfs tmpfs "${svcdir}" \
465 -o rw,mode=0644,size="${svcsize}"k
466 ;;
467 esac
468 eend 0
469 fi
470
471 # If booting off CD, we want to update inittab before setting the runlevel
472 if [ -f "/sbin/livecd-functions.sh" -a -n "${CDBOOT}" ]
473 then
474 ebegin "Updating inittab"
475 livecd_fix_inittab
476 eend $?
477 /sbin/telinit q &>/dev/null
478 fi
479
480 # Clear $svcdir from stale entries, but leave the caches around, as it
481 # should help speed things up a bit
482 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
483 grep -ve '\(depcache\|deptree\|envcache\)')
484
485 # Update the dependency cache
486 /sbin/depscan.sh -u
487
488 # Now that the dependency cache are up to date, make sure these
489 # are marked as started ...
490 (
491 # Needed for mark_service_started()
492 source "${svclib}/sh/rc-services.sh"
493
494 for x in ${CRITICAL_SERVICES}
495 do
496 mark_service_started "${x}"
497 done
498 )
499
500 # If the user's /dev/null or /dev/console are missing, we
501 # should help them out and explain how to rectify the situation
502 if [ ${dev_null} -eq 0 -o ${dev_console} -eq 0 ] \
503 && [ -e /usr/share/baselayout/issue.devfix ]
504 then
505 # Backup current /etc/issue
506 if [ -e /etc/issue -a ! -e /etc/issue.devfix ]
507 then
508 mv /etc/issue /etc/issue.devfix
509 fi
510
511 cp /usr/share/baselayout/issue.devfix /etc/issue
512 fi
513
514 # Setup login records ... this has to be done here because when
515 # we exit this runlevel, init will write a boot record to utmp
516 # If /var/run is readonly, then print a warning, not errors
517 if touch /var/run/utmp 2>/dev/null
518 then
519 > /var/run/utmp
520 touch /var/log/wtmp
521 chgrp utmp /var/run/utmp /var/log/wtmp
522 chmod 0664 /var/run/utmp /var/log/wtmp
523 # Remove /var/run/utmpx (bug from the past)
524 rm -f /var/run/utmpx
525 else
526 ewarn "Skipping /var/run/utmp initialization (ro root?)"
527 fi
528
529 exit 0
530 fi # Sysinit ends here
531
532 if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "boot" ]
533 then
534 setup_defaultlevels
535
536 if [ -n "${DEFAULTLEVEL}" -a "${DEFAULTLEVEL}" != "default" ]
537 then
538 # Setup our default runlevel runlevel that will be run
539 # the first time /sbin/rc is called with argv1 != sysinit|boot
540 echo "${DEFAULTLEVEL}" > "${svcdir}/ksoftlevel"
541 fi
542
543 # $BOOT can be used by rc-scripts to test if it is the first time
544 # the 'boot' runlevel is executed
545 export BOOT="yes"
546
547 # We reset argv1 to the bootlevel given on the kernel command line
548 # if there is one
549 argv1="${BOOTLEVEL}"
550
551 elif [ "${RUNLEVEL}" != "S" -a -e "${svcdir}/ksoftlevel" ]
552 then
553 argv1="$(< ${svcdir}/ksoftlevel)"
554 rm -f "${svcdir}/ksoftlevel"
555 fi
556
557 source "${svclib}/sh/rc-services.sh"
558 source "${svclib}/sh/rc-daemon.sh"
559
560 if [ -f "${svcdir}/softlevel" ]
561 then
562 # Set OLDSOFTLEVEL if we had a valid SOFTLEVEL
563 export OLDSOFTLEVEL="$(< ${svcdir}/softlevel)"
564 else
565 export OLDSOFTLEVEL=
566 fi
567
568 if [ -z "${argv1}" ]
569 then
570 if [ -f "${svcdir}/softlevel" ]
571 then
572 export SOFTLEVEL="$(< ${svcdir}/softlevel)"
573 else
574 export SOFTLEVEL="${BOOTLEVEL}"
575 fi
576 else
577 export SOFTLEVEL="${argv1}"
578 fi
579
580 if [ ! -f "${svcdir}/softlevel" ]
581 then
582 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
583 fi
584
585 # For keeping a list of services that fails during boot/halt
586 if [ ! -d "${svcdir}/failed" ]
587 then
588 mkdir -p -m 0755 "${svcdir}/failed"
589 else
590 rm -rf "${svcdir}"/failed/*
591 fi
592
593 splash "rc_init" "${argv1}"
594
595 if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
596 then
597 myscripts=
598
599 elif [ "${SOFTLEVEL}" = "single" ]
600 then
601 get_critical_services
602
603 myscripts="${CRITICAL_SERVICES}"
604
605 elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ]
606 then
607 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting ..."
608 exit 1
609 else
610 myscripts=
611 if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
612 then
613 # Normal runlevels *include* boot scripts
614 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
615 mylevels="${mylevels} $(dolisting /etc/runlevels/${BOOTLEVEL}/)"
616 else
617 # Non-normal runlevels don't include boot scripts as default
618 mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")"
619 fi
620
621 [ "${OLDSOFTLEVEL}" = "${BOOTLEVEL}" -o "${OLDSOFTLEVEL}" = "single" ] \
622 && /bin/dmesg -n 1
623
624 for x in ${mylevels}
625 do
626 [ -L "${x}" ] && myscripts="${myscripts} ${x##*/}"
627 done
628 fi
629
630 # The softscripts dir contains all scripts that belong to the
631 # runlevel specified in ${svcdir}/softlevel
632 # It needs to be a new directory, else when stopping the services
633 # and the old directory is not intact, things get broken
634
635 mkdir -p -m 0755 "${svcdir}/softscripts.new"
636
637 for x in ${myscripts}
638 do
639 if [ ! -e "/etc/init.d/${x}" ]
640 then
641 ewarn "WARNING: /etc/init.d/${x} missing; skipping ..."
642 continue
643 fi
644 # The -f eliminates a warning if the symlink already exists,
645 # which can happen if a service is in both the boot level and
646 # the current "normal" runlevel
647 ln -snf "/etc/init.d/${x}" "${svcdir}/softscripts.new/${x}"
648 done
649
650 dep_stop() {
651 local x=
652 local dep=
653 local needsme=
654 local myservice="${1##*/}"
655 local depservice=
656
657 if ! service_started "${myservice}"
658 then
659 return 0
660 fi
661
662 # Candidate for zapping
663 if [ ! -L "${svcdir}/softscripts.new/${myservice}" ]
664 then
665 # If this is a 'net' service, we do not want to stop it if it was
666 # not in the previous runlevel, and we are not shutting down,
667 # rebooting or going to single runlevel. This is because the user
668 # might have started it (net.ppp?), or possibly hotplug ...
669 if net_service "${myservice}" && \
670 [ "${SOFTLEVEL}" != "reboot" -a \
671 "${SOFTLEVEL}" != "shutdown" -a \
672 "${SOFTLEVEL}" != "single" ]
673 then
674 if [ -n "${OLDSOFTLEVEL}" ] && \
675 ! in_runlevel "${myservice}" "${OLDSOFTLEVEL}"
676 then
677 # This service is not in the previous runlevel, so
678 # do not stop it ...
679 return 0
680 fi
681 fi
682
683 # Should not work for 'use'
684 if [ -z "$(needsme "${myservice}")" ]
685 then
686 # Nothing depends on me
687 stop_service "${myservice}"
688 else
689 # Something may depend on me
690 needsme=0
691
692 for dep in $(needsme "${myservice}")
693 do
694 if service_started "${dep}" && \
695 [ -L "${svcdir}/softscripts.new/${dep}" ]
696 then
697 # This dep is valid
698 needsme=1
699
700 break
701 fi
702 done
703
704 if [ "${needsme}" -eq 0 ]
705 then
706 stop_service "${myservice}"
707 fi
708 fi
709 fi
710 }
711
712 # Stop services
713 if [ "${SOFTLEVEL}" != "single" -a \
714 "${SOFTLEVEL}" != "reboot" -a \
715 "${SOFTLEVEL}" != "shutdown" ]
716 then
717 for i in $(dolisting "${svcdir}/started/")
718 do
719 dep_stop "${i}"
720 done
721 else
722 get_critical_services
723
724 is_critical_service() {
725 local x=
726 local myservice="${1##*/}"
727
728 for x in ${CRITICAL_SERVICES}
729 do
730 if [ "${myservice}" = "${x}" ]
731 then
732 return 0
733 fi
734 done
735
736 return 1
737 }
738
739 # First stop non critical services
740 for i in $(dolisting "${svcdir}/started/")
741 do
742 if [ -n "${LOGGER_SERVICE}" ]
743 then
744 # Only stop it if the logger do not depends on it
745 if ! query_before "${i##*/}" "${LOGGER_SERVICE}"
746 then
747 continue
748 fi
749 fi
750
751 # Do not stop critical services just yet
752 is_critical_service "${i}" || dep_stop "${i}"
753 done
754
755 # Now stop the logger if running
756 if [ -n "${LOGGER_SERVICE}" ]
757 then
758 dep_stop "${LOGGER_SERVICE}"
759 fi
760
761 # Now stop the rest
762 for i in $(dolisting "${svcdir}/started/")
763 do
764 dep_stop "${i}"
765 done
766 fi
767
768 # Only change softlevel AFTER all the services have been stopped,
769 # else they will not get the depend's right (wrong SOFTLEVEL)
770
771 echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
772
773 if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ]
774 then
775 source /sbin/functions.sh
776
777 # Clear $svcdir from stale entries, but leave the caches around, as it
778 # should help speed things up a bit
779 rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \
780 grep -ve '\(depcache\|deptree\|envcache\)')
781
782 source /etc/init.d/halt.sh
783
784 if [ "${SOFTLEVEL}" = "reboot" ]
785 then
786 source /etc/init.d/reboot.sh
787 else
788 source /etc/init.d/shutdown.sh
789 fi
790
791 # Should never get here
792 exit 0
793 fi
794
795 # Move the old softscritps directory to a different one
796 # and make the new softscripts directory the current
797
798 mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old"
799 mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts"
800
801 dep_start() {
802 local myservice="${1##*/}"
803
804 [ ! -L "${svcdir}/softscripts/${myservice}" ] && continue
805
806 # Only start a script if it isn't already running
807 service_started "${myservice}" || schedule_service_startup "${myservice}"
808 }
809
810 get_critical_services
811
812 EXTRA_SOFTSCRIPTS="${CRITICAL_SERVICES}"
813
814 if [ -n "${LOGGER_SERVICE}" -a -L "${svcdir}/softscripts/${LOGGER_SERVICE}" ]
815 then
816 service_started "${LOGGER_SERVICE}" || \
817 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${LOGGER_SERVICE}"
818 fi
819
820 if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
821 then
822 for i in $(dolisting "/etc/runlevels/${BOOTLEVEL}/")
823 do
824 [ -L "${svcdir}/softscripts/${i##*/}" ] && \
825 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${i##*/}"
826 done
827 fi
828
829 # Start scripts
830 for i in ${EXTRA_SOFTSCRIPTS} $(dolisting "${svcdir}/softscripts/")
831 do
832 dep_start "${i##*/}"
833 done
834
835 # Wait for any services that may still be running ...
836 [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait
837
838 # Clean the old runlevel
839 rm -rf "${svcdir}/softscripts.old" &>/dev/null
840
841 # Depends gets nuked, so update them
842 # (this problem should be solved now, but i think it will be a good idea
843 # to recreate the deps after a change in runlevel)
844
845 #/sbin/depscan.sh &>/dev/null
846
847 # We want devfsd running after a change of runlevel (this is mostly if we return
848 # from runlevel 'single')
849 if [ -z "`ps --no-heading -C 'devfsd'`" -a \
850 -n "`gawk '/\/dev devfs/ { print }' /proc/mounts 2>/dev/null`" ]
851 then
852 if [ "${RC_DEVFSD_STARTUP}" != "no" ]
853 then
854 /sbin/devfsd /dev &>/dev/null
855 fi
856 fi
857
858 # Runlevel end, so clear stale fail list
859 rm -rf "${svcdir}/failed" &>/dev/null
860
861 # If we were in the boot runlevel, it is done now ...
862 [ -n "${BOOT}" ] && unset BOOT
863
864 splash "rc_exit"
865
866 # 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