Skip to content

Commit 20a576b

Browse files
Daniil FedotovGerhard Lazu
authored andcommitted
Ensure rabbit is running after the boot process finishes
Boot process can exit if boot fails. It can result in rabbit:await_startup/0 returning ok & rabbitmqctl wait exiting with exit status 0. WIP, still need to add some tests. Signed-off-by: Gerhard Lazu <[email protected]> re #1214 [#145043957]
1 parent 9e1235c commit 20a576b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/rabbit.erl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
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,
22+
stop_and_halt/0, await_startup/0, await_startup2/0, status/0, is_running/0,
2323
is_running/1, environment/0, rotate_logs/1, force_event_refresh/1,
2424
start_fhc/0]).
2525
-export([start/2, stop/1]).
@@ -436,7 +436,7 @@ stop() ->
436436
undefined -> ok;
437437
_ ->
438438
rabbit_log:info("RabbitMQ hasn't finished starting yet. Waiting for startup to finish before stopping..."),
439-
await_startup(true)
439+
wait_to_finish_booting()
440440
end,
441441
rabbit_log:info("RabbitMQ is asked to stop...~n", []),
442442
Apps = ?APPS ++ rabbit_plugins:active(),
@@ -619,6 +619,35 @@ await_startup(HaveSeenRabbitBoot) ->
619619
await_startup(true)
620620
end.
621621

622+
await_startup2() ->
623+
case is_booting() of
624+
true -> wait_to_finish_booting();
625+
false ->
626+
case is_running() of
627+
true -> ok;
628+
false -> wait_to_start_booting(),
629+
wait_to_finish_booting()
630+
end
631+
end.
632+
633+
is_booting() ->
634+
whereis(rabbit_boot) /= undefined.
635+
636+
wait_to_start_booting() ->
637+
case whereis(rabbit_boot) of
638+
undefined -> timer:sleep(100),
639+
wait_to_start_booting();
640+
_ -> ok
641+
end.
642+
643+
wait_to_finish_booting() ->
644+
case whereis(rabbit_boot) of
645+
undefined -> true = is_running(),
646+
ok;
647+
_ -> timer:sleep(100),
648+
wait_to_finish_booting()
649+
end.
650+
622651
status() ->
623652
S1 = [{pid, list_to_integer(os:getpid())},
624653
%% The timeout value used is twice that of gen_server:call/2.

src/rabbit_control_main.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ wait_for_application(Node, Pid, Application) ->
787787

788788
wait_for_startup(Node, Pid) ->
789789
while_process_is_alive(
790-
Node, Pid, fun() -> rpc:call(Node, rabbit, await_startup, []) =:= ok end).
790+
Node, Pid, fun() -> rpc:call(Node, rabbit, await_startup2, []) =:= ok end).
791791

792792
while_process_is_alive(Node, Pid, Activity) ->
793793
case rabbit_misc:is_os_process_alive(Pid) of

0 commit comments

Comments
 (0)