/[baselayout]/trunk/sbin/rc
Gentoo

Diff of /trunk/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 388 Revision 389
55 /bin/mount -a -o remount,ro & >/dev/null 55 /bin/mount -a -o remount,ro & >/dev/null
56 einfo "Rebooting" 56 einfo "Rebooting"
57 /sbin/reboot -f 57 /sbin/reboot -f
58 fi 58 fi
59 fi 59 fi
60
61 return 0
62}
63
64get_critical_services() {
65 local x=
66 CRITICAL_SERVICES=
67
68 if [ -f "/etc/runlevels/${BOOTLEVEL}/.critical" ]
69 then
70 for x in $(< /etc/runlevels/${BOOTLEVEL}/.critical)
71 do
72 CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}"
73 done
74 else
75 CRITICAL_SERVICES="checkroot hostname modules checkfs localmount"
76 fi
77
78 export CRITICAL_SERVICES
79
80 return 0
60} 81}
61 82
62# Save $1 83# Save $1
63argv1="$1" 84argv1="$1"
64 85
215 /bin/dmesg -n 1 236 /bin/dmesg -n 1
216 237
217 # We set the forced softlevel from the kernel command line 238 # We set the forced softlevel from the kernel command line
218 # It needs to be run right after proc is mounted for the 239 # It needs to be run right after proc is mounted for the
219 # boot runlevel 240 # boot runlevel
220 get_bootconfig 241 setup_defaultlevels
221 242
222 # $BOOT can be used by rc-scripts to test if it is the first time 243 # $BOOT can be used by rc-scripts to test if it is the first time
223 # the 'boot' runlevel is executed. Now also needed by some stuff in 244 # the 'boot' runlevel is executed. Now also needed by some stuff in
224 # the 'sysinit' runlevel ... 245 # the 'sysinit' runlevel ...
225 export BOOT="yes" 246 export BOOT="yes"
226 247
227 # Set SOFTLEVEL in case something needs it ...
228 export SOFTLEVEL="${BOOTLEVEL}"
229
230 start_critical_service() { 248 start_critical_service() {
231 local retval= 249 local retval=
232 250
233 source "/etc/init.d/${x}" || error "Failed to source /etc/init.d/${x}" 251 source "/etc/init.d/${x}" || error "Failed to source /etc/init.d/${x}"
234 retval=$? 252 retval=$?
237 start || eerror "Failed to start /etc/init.d/${x}" 255 start || eerror "Failed to start /etc/init.d/${x}"
238 retval=$? 256 retval=$?
239 257
240 return "${retval}" 258 return "${retval}"
241 } 259 }
242
243 260
244 # We first try to find a locally defined list of critical services 261 # We first try to find a locally defined list of critical services
245 # for a particular runlevel. If we cannot find it, we use the 262 # for a particular runlevel. If we cannot find it, we use the
246 # defaults. 263 # defaults.
247 if [ -f /etc/runlevels/${BOOTLEVEL}/critical ] 264 get_critical_services
248 then
249 CRITICAL_SERVICES="$(< /etc/runlevels/${BOOTLEVEL}/critical)"
250 else
251 CRITICAL_SERVICES="checkroot hostname modules checkfs localmount"
252 fi
253 265
254 # We do not want to break compadibility, so we do not fully integrate 266 # We do not want to break compadibility, so we do not fully integrate
255 # these into /sbin/rc, but rather start them by hand ... 267 # these into /sbin/rc, but rather start them by hand ...
256 for x in ${CRITICAL_SERVICES} 268 for x in ${CRITICAL_SERVICES}
257 do 269 do
284 # Update the dependency cache 296 # Update the dependency cache
285 /sbin/depscan.sh 297 /sbin/depscan.sh
286 298
287 # Now that the dependency cache are up to date, make sure these 299 # Now that the dependency cache are up to date, make sure these
288 # are marked as started ... 300 # are marked as started ...
301 (
302 # Needed for mark_service_started()
303 source "${svclib}/sh/rc-services.sh"
304
289 for x in ${CRITICAL_SERVICES} 305 for x in ${CRITICAL_SERVICES}
290 do 306 do
291 ln -snf "/etc/init.d/${x}" "${svcdir}/started/${x}" 307 mark_service_started "${x}"
292 done 308 done
309 )
293fi # Sysinit ends here 310fi # Sysinit ends here
294 311
295if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "sysinit" ] 312if [ "${RUNLEVEL}" = "S" -a "${argv1}" = "sysinit" ]
296then 313then
297 exit 0 314 exit 0
298 315
299elif [ "${RUNLEVEL}" = "S" -a "${argv1}" = "boot" ] 316elif [ "${RUNLEVEL}" = "S" -a "${argv1}" = "boot" ]
300then 317then
301 get_bootconfig 318 setup_defaultlevels
302 319
303 if [ -n "${SOFTLEVEL}" ] 320 if [ -n "${DEFAULTLEVEL}" -a "${DEFAULTLEVEL}" != "default" ]
304 then 321 then
322 # Setup our default runlevel runlevel that will be run
323 # the first time /sbin/rc is called with argv1 != sysinit|boot
305 echo "${SOFTLEVEL}" > "${svcdir}/ksoftlevel" 324 echo "${DEFAULTLEVEL}" > "${svcdir}/ksoftlevel"
306 fi 325 fi
307 326
308 # $BOOT can be used by rc-scripts to test if it is the first time 327 # $BOOT can be used by rc-scripts to test if it is the first time
309 # the 'boot' runlevel is executed 328 # the 'boot' runlevel is executed
310 export BOOT="yes" 329 export BOOT="yes"
311 330
312 # Set SOFTLEVEL so long as something may need it ...
313 export SOFTLEVEL="${BOOTLEVEL}"
314
315 # We reset argv1 to the bootlevel given on the kernel command line 331 # We reset argv1 to the bootlevel given on the kernel command line
316 # if there is one 332 # if there is one
317 argv1="${BOOTLEVEL}" 333 argv1="${BOOTLEVEL}"
318 334
319elif [ "${RUNLEVEL}" != "S" -a -e "${svcdir}/ksoftlevel" ] 335elif [ "${RUNLEVEL}" != "S" -a -e "${svcdir}/ksoftlevel" ]
363then 379then
364 myscripts= 380 myscripts=
365 381
366elif [ "${SOFTLEVEL}" = "single" ] 382elif [ "${SOFTLEVEL}" = "single" ]
367then 383then
368 myscripts="checkroot hostname modules checkfs localmount" 384 get_critical_services
385
386 myscripts="${CRITICAL_SERVICES}"
369 387
370elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ] 388elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ]
371then 389then
372 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting..." 390 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting..."
373 exit 1 391 exit 1
414 432
415dep_stop() { 433dep_stop() {
416 local x= 434 local x=
417 local dep= 435 local dep=
418 local needsme= 436 local needsme=
419 local myservice= 437 local myservice="${1##*/}"
420 local depservice= 438 local depservice=
439
440 [ ! -L "${svcdir}/started/${myservice}" ] && continue
421 441
422 [ ! -L "$1" ] && continue 442 if [ ! -e "${svcdir}/started/${myservice}" ]
423
424 if [ ! -e "$1" ]
425 then 443 then
426 # Remove dud symlinks 444 # Remove dud symlinks
427 rm -f "$1" 445 rm -f "${svcdir}/started/${myservice}"
428 446
429 continue 447 continue
430 fi 448 fi
431 449
432 myservice="${1##*/}"
433
434 # Candidate for zapping 450 # Candidate for zapping
435 if [ ! -L "${svcdir}/softscripts.new/${myservice}" ] 451 if [ ! -L "${svcdir}/softscripts.new/${myservice}" ]
436 then 452 then
437 # If this is a 'net' service, we do not want to stop it if it was 453 # If this is a 'net' service, we do not want to stop it if it was
438 # not in the previous runlevel, and we are not shutting down, 454 # not in the previous runlevel, and we are not shutting down,
481 fi 497 fi
482 fi 498 fi
483} 499}
484 500
485# Stop services 501# Stop services
502if [ "${SOFTLEVEL}" != "single" -a \
503 "${SOFTLEVEL}" != "reboot" -a \
504 "${SOFTLEVEL}" != "shutdown" ]
505then
486for i in $(dolisting "${svcdir}/started/") 506 for i in $(dolisting "${svcdir}/started/")
487do 507 do
488 dep_stop "${i}" 508 dep_stop "${i}"
489done 509 done
510else
511 get_critical_services
512
513 is_critical_service() {
514 local x=
515 local myservice="${1##*/}"
516
517 for x in ${CRITICAL_SERVICES}
518 do
519 if [ "${myservice}" = "${x}" ]
520 then
521 return 0
522 fi
523 done
524
525 return 1
526 }
527
528 # First stop non critical services
529 for i in $(dolisting "${svcdir}/started/")
530 do
531 if [ -n "${LOGGER_SERVICE}" ]
532 then
533 # Do not stop it if it depends on the logger
534 if query_before "${i##*/}" "${LOGGER_SERVICE}"
535 then
536 # Same if it is a critical service
537 is_critical_service "${i}" || dep_stop "${i}"
538 fi
539 else
540 is_critical_service "${i}" || dep_stop "${i}"
541 fi
542 done
543
544 # Now stop the logger if running
545 if [ -n "${LOGGER_SERVICE}" ]
546 then
547 service_started "${LOGGER_SERVICE}" && dep_stop "${LOGGER_SERVICE}"
548 fi
549
550 # Now stop the rest
551 for i in $(dolisting "${svcdir}/started/")
552 do
553 dep_stop "${i}"
554 done
555fi
490 556
491# Only change softlevel AFTER all the services have been stopped, 557# Only change softlevel AFTER all the services have been stopped,
492# else they will not get the depend's right (wrong SOFTLEVEL) 558# else they will not get the depend's right (wrong SOFTLEVEL)
493 559
494echo "${SOFTLEVEL}" > "${svcdir}/softlevel" 560echo "${SOFTLEVEL}" > "${svcdir}/softlevel"
518 584
519mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old" 585mv -f "${svcdir}/softscripts" "${svcdir}/softscripts.old"
520mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts" 586mv -f "${svcdir}/softscripts.new" "${svcdir}/softscripts"
521 587
522dep_start() { 588dep_start() {
523 local myservice=
524
525 [ ! -L "$1" ] && continue
526
527 myservice="${1##*/}" 589 local myservice="${1##*/}"
528 590
591 [ ! -L "${svcdir}/softscripts/${myservice}" ] && continue
592
529 # Only start a script if it isn't already running 593 # Only start a script if it isn't already running
530 service_started "${myservice}" || schedule_service_startup "${myservice}" 594 service_started "${myservice}" || schedule_service_startup "${myservice}"
531} 595}
532 596
597get_critical_services
598
599EXTRA_SOFTSCRIPTS="${CRITICAL_SERVICES}"
600
601if [ -n "${LOGGER_SERVICE}" -a -L "${svcdir}/softscripts/${LOGGER_SERVICE}" ]
602then
603 service_started "${LOGGER_SERVICE}" || \
604 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${LOGGER_SERVICE}"
605fi
606
607if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ]
608then
609 for i in $(dolisting "/etc/runlevels/${BOOTLEVEL}/")
610 do
611 [ -L "${svcdir}/softscripts/${i##*/}" ] && \
612 EXTRA_SOFTSCRIPTS="${EXTRA_SOFTSCRIPTS} ${i##*/}"
613 done
614fi
615
533# Start scripts 616# Start scripts
534for i in $(dolisting "${svcdir}/softscripts/") 617for i in ${EXTRA_SOFTSCRIPTS} $(dolisting "${svcdir}/softscripts/")
535do 618do
536 dep_start "${i}" 619 dep_start "${i}"
537done 620done
538 621
539# Wait for any services that may still be running ... 622# Wait for any services that may still be running ...

Legend:
Removed from v.388  
changed lines
  Added in v.389

  ViewVC Help
Powered by ViewVC 1.1.20