Lines 397-402
Link Here
|
397 |
return 1 |
397 |
return 1 |
398 |
} |
398 |
} |
399 |
|
399 |
|
|
|
400 |
# bool begin_exclusive( service ) |
401 |
# |
402 |
# atomically marks the service as being executed |
403 |
# use like this: |
404 |
# |
405 |
# if begion_exclusive myexclusive ; then |
406 |
# whatever is in here can only be executed by one process |
407 |
# end_exclusive myexclusive |
408 |
# fi |
409 |
|
410 |
begin_service() |
411 |
{ |
412 |
[ "$START_CRITICAL" == "yes" ] && return 0 |
413 |
|
414 |
mkfifo "${svcdir}/exclusive/$1" &> /dev/null |
415 |
return $? |
416 |
} |
417 |
|
418 |
# void end_exclusive(service, exitcode) |
419 |
# |
420 |
# stops executing a exclusive region and |
421 |
# wakes up anybody who is waiting for the exclusive region |
422 |
# |
423 |
end_service() |
424 |
{ |
425 |
local newname |
426 |
|
427 |
# if we are doing critical services, there is no fifo |
428 |
|
429 |
[ "$START_CRITICAL" == "yes" ] && return |
430 |
|
431 |
if [ -n "$2" ] ; then |
432 |
echo "$2" > "${svcdir}/exitcodes/$1" |
433 |
fi |
434 |
|
435 |
# move the fifo to a unique name so noone is waiting for it after we touch it |
436 |
newname="$(mktemp "${svcdir}/exclusive/$1.XXXXXXXXXX")" |
437 |
mv -f "${svcdir}/exclusive/$1" "${newname}" |
438 |
|
439 |
# wake up anybody that was waiting for the fifo |
440 |
touch "${newname}" |
441 |
|
442 |
# We dont need the fifo anymore |
443 |
rm -f "${newname}" |
444 |
} |
445 |
|
446 |
# int wait_exclusive(service) |
447 |
|
448 |
wait_service() |
449 |
{ |
450 |
|
451 |
local retval |
452 |
|
453 |
[ "$START_CRITICAL" == "yes" ] && return 0 |
454 |
|
455 |
# this will block until the fifo is touched. It is touched by calling end_exclusive |
456 |
# if no begin_eclusive has being called or end_exclusive has already finished |
457 |
# this will not block |
458 |
cat "${svcdir}/exclusive/$1" 2> /dev/null |
459 |
retval="$( cat "${svcdir}/exitcodes/$1")" |
460 |
return "${retval}" |
461 |
} |
462 |
|
400 |
# int start_service(service) |
463 |
# int start_service(service) |
401 |
# |
464 |
# |
402 |
# Start 'service' if it is not already running. |
465 |
# Start 'service' if it is not already running. |
Lines 406-426
Link Here
|
406 |
|
469 |
|
407 |
[ -z "$1" ] && return 1 |
470 |
[ -z "$1" ] && return 1 |
408 |
|
471 |
|
409 |
if ! service_started "$1" |
472 |
#critical services can not start in parallel and begin_service fails because |
410 |
then |
473 |
#we don't have write permition to ${svcdir} |
411 |
splash "svc_start" "$1" |
474 |
# so if we are doing critical services, disable the parallel feature |
412 |
|
475 |
|
413 |
if is_fake_service "$1" "${SOFTLEVEL}" |
476 |
# if it is not currently running or we are doing critical services |
414 |
then |
477 |
if begin_service "$1" ; then |
415 |
mark_service_started "$1" |
478 |
|
416 |
splash "svc_started" "$1" "0" |
479 |
|
417 |
else |
480 |
|
418 |
(. /sbin/runscript.sh "/etc/init.d/$1" start) |
481 |
if ! service_started "$1" |
419 |
retval="$?" |
482 |
then |
420 |
splash "svc_started" "$1" "${retval}" |
483 |
splash "svc_start" "$1" |
421 |
return "${retval}" |
484 |
if is_fake_service "$1" "${SOFTLEVEL}" |
422 |
fi |
485 |
then |
423 |
fi |
486 |
mark_service_started "$1" |
|
|
487 |
splash "svc_started" "$1" "0" |
488 |
end_service "$1" "0" |
489 |
else |
490 |
( |
491 |
|
492 |
(. /sbin/runscript.sh "/etc/init.d/$1" start) |
493 |
retval="$?" |
494 |
splash "svc_started" "$1" "${retval}" |
495 |
end_service "$1" "${retval}" |
496 |
) & |
497 |
|
498 |
# if startup is not parallel, or we are doing criticall services |
499 |
if [ "${RC_PARALLEL_STARTUP}" != "yes" -o "$START_CRITICAL" == "yes" ] ; then |
500 |
wait |
501 |
fi |
502 |
|
503 |
fi |
504 |
else |
505 |
end_service "$1" |
506 |
fi |
507 |
fi |
508 |
|
424 |
|
509 |
|
425 |
return 0 |
510 |
return 0 |
426 |
} |
511 |
} |
Lines 471-476
Link Here
|
471 |
mark_service_started() { |
556 |
mark_service_started() { |
472 |
[ -z "$1" ] && return 1 |
557 |
[ -z "$1" ] && return 1 |
473 |
|
558 |
|
|
|
559 |
echo "0" > "${svcdir}/exitcodes/$1" |
560 |
|
474 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
561 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
475 |
|
562 |
|
476 |
return $? |
563 |
return $? |
Lines 594-653
Link Here
|
594 |
# Schedule 'service' for startup, in parallel if possible. |
681 |
# Schedule 'service' for startup, in parallel if possible. |
595 |
# |
682 |
# |
596 |
schedule_service_startup() { |
683 |
schedule_service_startup() { |
597 |
local count=0 |
684 |
if ! iparallel "$1" |
598 |
local current_job= |
|
|
599 |
|
600 |
if [ "${RC_PARALLEL_STARTUP}" = "yes" ] |
601 |
then |
685 |
then |
602 |
set -m +b |
686 |
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 |
687 |
fi |
|
|
688 |
|
689 |
start_service "$1" |
651 |
|
690 |
|
652 |
# We do not need to check the return value here, as svc_{start,stop}() do |
691 |
# We do not need to check the return value here, as svc_{start,stop}() do |
653 |
# their own error handling ... |
692 |
# their own error handling ... |