Lines 397-427
Link Here
|
397 |
return 1 |
397 |
return 1 |
398 |
} |
398 |
} |
399 |
|
399 |
|
|
|
400 |
# bool begin_service( service ) |
401 |
# |
402 |
# atomically marks the service as being executed |
403 |
# use like this: |
404 |
# |
405 |
# if begion_service service ; then |
406 |
# whatever is in here can only be executed by one process |
407 |
# end_service service |
408 |
# fi |
409 |
|
410 |
begin_service() |
411 |
{ |
412 |
local service="$1" |
413 |
[ "$START_CRITICAL" == "yes" ] && return 0 |
414 |
|
415 |
mkfifo "${svcdir}/exclusive/${service}" &> /dev/null |
416 |
return $? |
417 |
} |
418 |
|
419 |
# void end_exclusive(service, exitcode) |
420 |
# |
421 |
# stops executing a exclusive region and |
422 |
# wakes up anybody who is waiting for the exclusive region |
423 |
# |
424 |
end_service() |
425 |
{ |
426 |
local service="$1" |
427 |
local exitstatus="$2" |
428 |
local tempname |
429 |
|
430 |
# if we are doing critical services, there is no fifo |
431 |
|
432 |
[ "$START_CRITICAL" == "yes" ] && return |
433 |
|
434 |
if [ -n "${exitstatus}" ] ; then |
435 |
echo "${exitstatus}" > "${svcdir}/exitcodes/${service}" |
436 |
fi |
437 |
|
438 |
# move the fifo to a unique name so noone is waiting for it after we touch it |
439 |
tempname="$(mktemp "${svcdir}/exclusive/${service}.XXXXXXXXXX")" |
440 |
mv -f "${svcdir}/exclusive/${service}" "${tempname}" |
441 |
|
442 |
# wake up anybody that was waiting for the fifo |
443 |
touch "${tempname}" |
444 |
|
445 |
# We dont need the fifo anymore |
446 |
rm -f "${tempname}" |
447 |
} |
448 |
|
449 |
# int wait_exclusive(service) |
450 |
|
451 |
wait_service() |
452 |
{ |
453 |
local service="$1" |
454 |
local exitstatus |
455 |
|
456 |
[ "$START_CRITICAL" == "yes" ] && return 0 |
457 |
|
458 |
# this will block until the fifo is touched. It is touched by calling end_exclusive |
459 |
# if no begin_eclusive has being called or end_exclusive has already finished |
460 |
# this will not block |
461 |
cat "${svcdir}/exclusive/${service}" 2> /dev/null |
462 |
exitstatus="$( cat "${svcdir}/exitcodes/${service}")" |
463 |
return "${exitstatus}" |
464 |
} |
465 |
|
400 |
# int start_service(service) |
466 |
# int start_service(service) |
401 |
# |
467 |
# |
402 |
# Start 'service' if it is not already running. |
468 |
# Start 'service' if it is not already running. |
403 |
# |
469 |
# |
404 |
start_service() { |
470 |
start_service() { |
|
|
471 |
local service="$1" |
405 |
local retval=0 |
472 |
local retval=0 |
|
|
473 |
|
474 |
[ -z "${service}" ] && return 1 |
406 |
|
475 |
|
407 |
[ -z "$1" ] && return 1 |
476 |
#critical services can not start in parallel and begin_service fails because |
408 |
|
477 |
#we don't have write permition to ${svcdir} |
409 |
if ! service_started "$1" |
478 |
# so if we are doing critical services, disable the parallel feature |
410 |
then |
479 |
|
411 |
splash "svc_start" "$1" |
480 |
# if it is not currently running or we are doing critical services |
|
|
481 |
if begin_service "${service}" ; then |
482 |
|
483 |
|
484 |
|
485 |
if ! service_started "${service}" |
486 |
then |
487 |
splash "svc_start" "${service}" |
488 |
if is_fake_service "${service}" "${SOFTLEVEL}" |
489 |
then |
490 |
mark_service_started "${service}" |
491 |
splash "svc_started" "${service}" "0" |
492 |
end_service "${service}" "0" |
493 |
else |
412 |
|
494 |
|
413 |
if is_fake_service "$1" "${SOFTLEVEL}" |
495 |
if [ "${RC_PARALLEL_STARTUP}" != "yes" -o "$START_CRITICAL" == "yes" ] |
414 |
then |
496 |
then |
415 |
mark_service_started "$1" |
497 |
|
416 |
splash "svc_started" "$1" "0" |
498 |
# if we can not start the services in parallel, then just start it and return the exit status |
|
|
499 |
(. /sbin/runscript.sh "/etc/init.d/${service}" start) |
500 |
retval="$?" |
501 |
splash "svc_started" "${service}" "${retval}" |
502 |
end_service "${service}" "${retval}" |
503 |
return "${retval}" |
504 |
else |
505 |
# if parallel startup is allowed, start it in background |
506 |
( |
507 |
|
508 |
(. /sbin/runscript.sh "/etc/init.d/${service}" start) |
509 |
retval="$?" |
510 |
splash "svc_started" "${service}" "${retval}" |
511 |
end_service "${service}" "${retval}" |
512 |
) & |
513 |
|
514 |
fi |
515 |
fi |
417 |
else |
516 |
else |
418 |
(. /sbin/runscript.sh "/etc/init.d/$1" start) |
517 |
end_service "${service}" |
419 |
retval="$?" |
|
|
420 |
splash "svc_started" "$1" "${retval}" |
421 |
return "${retval}" |
422 |
fi |
518 |
fi |
423 |
fi |
519 |
fi |
424 |
|
520 |
|
|
|
521 |
|
425 |
return 0 |
522 |
return 0 |
426 |
} |
523 |
} |
427 |
|
524 |
|
Lines 471-476
Link Here
|
471 |
mark_service_started() { |
568 |
mark_service_started() { |
472 |
[ -z "$1" ] && return 1 |
569 |
[ -z "$1" ] && return 1 |
473 |
|
570 |
|
|
|
571 |
echo "0" > "${svcdir}/exitcodes/$1" |
572 |
|
474 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
573 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
475 |
|
574 |
|
476 |
return $? |
575 |
return $? |
Lines 594-653
Link Here
|
594 |
# Schedule 'service' for startup, in parallel if possible. |
693 |
# Schedule 'service' for startup, in parallel if possible. |
595 |
# |
694 |
# |
596 |
schedule_service_startup() { |
695 |
schedule_service_startup() { |
597 |
local count=0 |
696 |
local service="$1" |
598 |
local current_job= |
697 |
|
599 |
|
698 |
if ! iparallel "${service}" |
600 |
if [ "${RC_PARALLEL_STARTUP}" = "yes" ] |
|
|
601 |
then |
699 |
then |
602 |
set -m +b |
700 |
wait |
603 |
|
|
|
604 |
if [ "$(jobs | grep -c "Running")" -gt 0 ] |
605 |
then |
606 |
if [ "$(jobs | grep -c "Running")" -eq 1 ] |
607 |
then |
608 |
if [ -n "$(jobs)" ] |
609 |
then |
610 |
current_job="$(jobs | awk '/Running/ { print $4}')" |
611 |
fi |
612 |
|
613 |
# Wait if we cannot start this service with the already running |
614 |
# one (running one might start this one ...). |
615 |
query_before "$1" "${current_job}" && wait |
616 |
|
617 |
elif [ "$(jobs | grep -c "Running")" -ge 2 ] |
618 |
then |
619 |
count="$(jobs | grep -c "Running")" |
620 |
|
621 |
# Wait until we have only one service running |
622 |
while [ "${count}" -gt 1 ] |
623 |
do |
624 |
count="$(jobs | grep -c "Running")" |
625 |
done |
626 |
|
627 |
if [ -n "$(jobs)" ] |
628 |
then |
629 |
current_job="$(jobs | awk '/Running/ { print $4}')" |
630 |
fi |
631 |
|
632 |
# Wait if we cannot start this service with the already running |
633 |
# one (running one might start this one ...). |
634 |
query_before "$1" "${current_job}" && wait |
635 |
fi |
636 |
fi |
637 |
|
638 |
if iparallel "$1" |
639 |
then |
640 |
eval start_service "$1" \& |
641 |
else |
642 |
# Do not start with any service running if we cannot start |
643 |
# this service in parallel ... |
644 |
# wait |
645 |
|
646 |
start_service "$1" |
647 |
fi |
648 |
else |
649 |
start_service "$1" |
650 |
fi |
701 |
fi |
|
|
702 |
|
703 |
start_service "${service}" |
651 |
|
704 |
|
652 |
# We do not need to check the return value here, as svc_{start,stop}() do |
705 |
# We do not need to check the return value here, as svc_{start,stop}() do |
653 |
# their own error handling ... |
706 |
# their own error handling ... |