Skip to content

Commit 8aa5c1f

Browse files
committed
one way to check whether rabbit is running
and avoid timeouts in application:which_applications() in doing so
1 parent a8c4a6c commit 8aa5c1f

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/rabbit.erl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
-behaviour(application).
2020

21-
-export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0, environment/0,
21+
-export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0,
22+
is_running/0 , is_running/1, environment/0,
2223
rotate_logs/1, force_event_refresh/0]).
2324

2425
-export([start/2, stop/1]).
@@ -196,6 +197,8 @@
196197
{os, {atom(), atom()}} |
197198
{erlang_version, string()} |
198199
{memory, any()}]).
200+
-spec(is_running/0 :: () -> boolean()).
201+
-spec(is_running/1 :: (node()) -> boolean()).
199202
-spec(environment/0 :: () -> [{atom() | term()}]).
200203
-spec(log_location/1 :: ('sasl' | 'kernel') -> log_location()).
201204

@@ -233,11 +236,19 @@ stop_and_halt() ->
233236

234237
status() ->
235238
[{pid, list_to_integer(os:getpid())},
236-
{running_applications, application:which_applications()},
239+
{running_applications, application:which_applications(infinity)},
237240
{os, os:type()},
238241
{erlang_version, erlang:system_info(system_version)},
239242
{memory, erlang:memory()}].
240243

244+
is_running() -> is_running(node()).
245+
246+
is_running(Node) ->
247+
case rpc:call(Node, application, which_applications, [infinity]) of
248+
{badrpc, _} -> false;
249+
Apps -> proplists:is_defined(rabbit, Apps)
250+
end.
251+
241252
environment() ->
242253
lists:keysort(
243254
1, [P || P = {K, _} <- application:get_all_env(rabbit),

src/rabbit_control.erl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ wait_for_application(Node, PidFile, Inform) ->
362362

363363
wait_for_application(Node, Pid) ->
364364
case process_up(Pid) of
365-
true -> case node_up(Node) of
365+
true -> case rabbit:is_running(Node) of
366366
true -> ok;
367367
false -> timer:sleep(1000),
368368
wait_for_application(Node, Pid)
@@ -378,12 +378,6 @@ wait_and_read_pid_file(PidFile) ->
378378
{error, _} = E -> exit({error, {could_not_read_pid, E}})
379379
end.
380380

381-
node_up(Node) ->
382-
case rpc_call(Node, application, which_applications, [infinity]) of
383-
{badrpc, _} -> false;
384-
Apps -> proplists:is_defined(rabbit, Apps)
385-
end.
386-
387381
% Test using some OS clunkiness since we shouldn't trust
388382
% rpc:call(os, getpid, []) at this point
389383
process_up(Pid) ->

src/rabbit_direct.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ list() ->
7272
%%----------------------------------------------------------------------------
7373

7474
connect(Username, VHost, Protocol, Pid, Infos) ->
75-
case lists:keymember(rabbit, 1, application:which_applications()) of
75+
case rabbit:is_running() of
7676
true ->
7777
case rabbit_access_control:check_user_login(Username, []) of
7878
{ok, User} ->

src/rabbit_upgrade.erl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,7 @@ secondary_upgrade(AllNodes) ->
228228
ok.
229229

230230
nodes_running(Nodes) ->
231-
[N || N <- Nodes, node_running(N)].
232-
233-
node_running(Node) ->
234-
case rpc:call(Node, application, which_applications, []) of
235-
{badrpc, _} -> false;
236-
Apps -> lists:keysearch(rabbit, 1, Apps) =/= false
237-
end.
231+
[N || N <- Nodes, rabbit:is_running(N)].
238232

239233
%% -------------------------------------------------------------------
240234

0 commit comments

Comments
 (0)