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-429
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 |
if is_fake_service "$1" "${SOFTLEVEL}" |
475 |
|
|
|
476 |
# if it is not currently running or we are doing critical services |
477 |
if begin_service "$1" ; then |
478 |
|
479 |
|
480 |
|
481 |
if ! service_started "$1" |
413 |
then |
482 |
then |
414 |
mark_service_started "$1" |
483 |
splash "svc_start" "$1" |
415 |
splash "svc_started" "$1" "0" |
484 |
if is_fake_service "$1" "${SOFTLEVEL}" |
|
|
485 |
then |
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 |
416 |
else |
504 |
else |
417 |
(. /sbin/runscript.sh "/etc/init.d/$1" start) |
505 |
end_service "$1" |
418 |
retval="$?" |
|
|
419 |
splash "svc_started" "$1" "${retval}" |
420 |
return "${retval}" |
421 |
fi |
506 |
fi |
422 |
fi |
507 |
fi |
423 |
|
508 |
|
424 |
return 0 |
509 |
return 0 |
425 |
} |
510 |
} |
426 |
|
511 |
|
|
|
512 |
|
427 |
# int stop_service(service) |
513 |
# int stop_service(service) |
428 |
# |
514 |
# |
429 |
# Stop 'service' if it is not already running. |
515 |
# Stop 'service' if it is not already running. |
Lines 469-474
Link Here
|
469 |
mark_service_started() { |
555 |
mark_service_started() { |
470 |
[ -z "$1" ] && return 1 |
556 |
[ -z "$1" ] && return 1 |
471 |
|
557 |
|
|
|
558 |
echo "0" > "${svcdir}/exitcodes/$1" |
559 |
|
472 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
560 |
ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" |
473 |
|
561 |
|
474 |
return $? |
562 |
return $? |
Lines 559-618
Link Here
|
559 |
# Schedule 'service' for startup, in parallel if possible. |
647 |
# Schedule 'service' for startup, in parallel if possible. |
560 |
# |
648 |
# |
561 |
schedule_service_startup() { |
649 |
schedule_service_startup() { |
562 |
local count=0 |
650 |
if ! iparallel "$1" |
563 |
local current_job= |
|
|
564 |
|
565 |
if [ "${RC_PARALLEL_STARTUP}" = "yes" ] |
566 |
then |
651 |
then |
567 |
set -m +b |
652 |
wait |
568 |
|
|
|
569 |
if [ "$(jobs | grep -c "Running")" -gt 0 ] |
570 |
then |
571 |
if [ "$(jobs | grep -c "Running")" -eq 1 ] |
572 |
then |
573 |
if [ -n "$(jobs)" ] |
574 |
then |
575 |
current_job="$(jobs | awk '/Running/ { print $4}')" |
576 |
fi |
577 |
|
578 |
# Wait if we cannot start this service with the already running |
579 |
# one (running one might start this one ...). |
580 |
query_before "$1" "${current_job}" && wait |
581 |
|
582 |
elif [ "$(jobs | grep -c "Running")" -ge 2 ] |
583 |
then |
584 |
count="$(jobs | grep -c "Running")" |
585 |
|
586 |
# Wait until we have only one service running |
587 |
while [ "${count}" -gt 1 ] |
588 |
do |
589 |
count="$(jobs | grep -c "Running")" |
590 |
done |
591 |
|
592 |
if [ -n "$(jobs)" ] |
593 |
then |
594 |
current_job="$(jobs | awk '/Running/ { print $4}')" |
595 |
fi |
596 |
|
597 |
# Wait if we cannot start this service with the already running |
598 |
# one (running one might start this one ...). |
599 |
query_before "$1" "${current_job}" && wait |
600 |
fi |
601 |
fi |
602 |
|
603 |
if iparallel "$1" |
604 |
then |
605 |
eval start_service "$1" \& |
606 |
else |
607 |
# Do not start with any service running if we cannot start |
608 |
# this service in parallel ... |
609 |
# wait |
610 |
|
611 |
start_service "$1" |
612 |
fi |
613 |
else |
614 |
start_service "$1" |
615 |
fi |
653 |
fi |
|
|
654 |
|
655 |
start_service "$1" |
616 |
|
656 |
|
617 |
# We do not need to check the return value here, as svc_{start,stop}() do |
657 |
# We do not need to check the return value here, as svc_{start,stop}() do |
618 |
# their own error handling ... |
658 |
# their own error handling ... |