|
19 | 19 | -behaviour(application).
|
20 | 20 |
|
21 | 21 | -export([start/0, boot/0, stop/0,
|
22 |
| - stop_and_halt/0, await_startup/0, status/0, is_running/0, alarms/0, |
| 22 | + stop_and_halt/0, await_startup/0, await_startup/1, |
| 23 | + status/0, is_running/0, alarms/0, |
23 | 24 | is_running/1, environment/0, rotate_logs/0, force_event_refresh/1,
|
24 | 25 | start_fhc/0]).
|
25 | 26 | -export([start/2, stop/1, prep_stop/1]).
|
@@ -473,7 +474,7 @@ stop() ->
|
473 | 474 | undefined -> ok;
|
474 | 475 | _ ->
|
475 | 476 | rabbit_log:info("RabbitMQ hasn't finished starting yet. Waiting for startup to finish before stopping..."),
|
476 |
| - wait_for_boot_to_finish() |
| 477 | + ok = wait_for_boot_to_finish(node()) |
477 | 478 | end,
|
478 | 479 | rabbit_log:info("RabbitMQ is asked to stop...~n", []),
|
479 | 480 | Apps = ?APPS ++ rabbit_plugins:active(),
|
@@ -647,32 +648,52 @@ handle_app_error(Term) ->
|
647 | 648 | end.
|
648 | 649 |
|
649 | 650 | await_startup() ->
|
650 |
| - case is_booting() of |
651 |
| - true -> wait_for_boot_to_finish(); |
| 651 | + await_startup(node()). |
| 652 | + |
| 653 | +await_startup(Node) -> |
| 654 | + case is_booting(Node) of |
| 655 | + true -> wait_for_boot_to_finish(Node); |
652 | 656 | false ->
|
653 |
| - case is_running() of |
| 657 | + case is_running(Node) of |
654 | 658 | true -> ok;
|
655 |
| - false -> wait_for_boot_to_start(), |
656 |
| - wait_for_boot_to_finish() |
| 659 | + false -> wait_for_boot_to_start(Node), |
| 660 | + wait_for_boot_to_finish(Node) |
657 | 661 | end
|
658 | 662 | end.
|
659 | 663 |
|
660 |
| -is_booting() -> |
661 |
| - whereis(rabbit_boot) /= undefined. |
| 664 | +is_booting(Node) -> |
| 665 | + case rpc:call(Node, erlang, whereis, [rabbit_boot]) of |
| 666 | + {badrpc, _} = Err -> Err; |
| 667 | + undefined -> false; |
| 668 | + P when is_pid(P) -> true |
| 669 | + end. |
662 | 670 |
|
663 |
| -wait_for_boot_to_start() -> |
664 |
| - case whereis(rabbit_boot) of |
665 |
| - undefined -> timer:sleep(100), |
666 |
| - wait_for_boot_to_start(); |
667 |
| - _ -> ok |
| 671 | +wait_for_boot_to_start(Node) -> |
| 672 | + case is_booting(Node) of |
| 673 | + false -> |
| 674 | + timer:sleep(100), |
| 675 | + wait_for_boot_to_start(Node); |
| 676 | + {badrpc, _} = Err -> |
| 677 | + Err; |
| 678 | + true -> |
| 679 | + ok |
668 | 680 | end.
|
669 | 681 |
|
670 |
| -wait_for_boot_to_finish() -> |
671 |
| - case whereis(rabbit_boot) of |
672 |
| - undefined -> true = is_running(), |
673 |
| - ok; |
674 |
| - _ -> timer:sleep(100), |
675 |
| - wait_for_boot_to_finish() |
| 682 | +wait_for_boot_to_finish(Node) -> |
| 683 | + case is_booting(Node) of |
| 684 | + false -> |
| 685 | + %% We don't want badrpc error to be interpreted as false, |
| 686 | + %% so we don't call rabbit:is_running(Node) |
| 687 | + case rpc:call(Node, rabbit, is_running, []) of |
| 688 | + true -> ok; |
| 689 | + false -> {error, rabbit_is_not_running}; |
| 690 | + {badrpc, _} = Err -> Err |
| 691 | + end; |
| 692 | + {badrpc, _} = Err -> |
| 693 | + Err; |
| 694 | + true -> |
| 695 | + timer:sleep(100), |
| 696 | + wait_for_boot_to_finish(Node) |
676 | 697 | end.
|
677 | 698 |
|
678 | 699 | status() ->
|
|
0 commit comments