Skip to content

Commit 04cadbc

Browse files
author
Daniil Fedotov
committed
Add an API to await for node startup from a remote node.
rabbitmqctl wait will have more flexibility if the rabbitmqctl node will do the waiting. For example when net_ticktime is lower than startup time wait would not fail.
1 parent fb82e4b commit 04cadbc

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

src/rabbit.erl

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
-behaviour(application).
2020

2121
-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,
2324
is_running/1, environment/0, rotate_logs/0, force_event_refresh/1,
2425
start_fhc/0]).
2526
-export([start/2, stop/1, prep_stop/1]).
@@ -473,7 +474,7 @@ stop() ->
473474
undefined -> ok;
474475
_ ->
475476
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())
477478
end,
478479
rabbit_log:info("RabbitMQ is asked to stop...~n", []),
479480
Apps = ?APPS ++ rabbit_plugins:active(),
@@ -647,32 +648,52 @@ handle_app_error(Term) ->
647648
end.
648649

649650
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);
652656
false ->
653-
case is_running() of
657+
case is_running(Node) of
654658
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)
657661
end
658662
end.
659663

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.
662670

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
668680
end.
669681

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)
676697
end.
677698

678699
status() ->

0 commit comments

Comments
 (0)