summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-08-25 22:31:00 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-08-25 22:31:00 +0100
commit4456a1a46b36b472cc29641cee5fe7e15da5393a (patch)
tree3760413417c6b641373dc4b3a60d49736583f84e
parent3b39cf36cdcee0cd1ae197238904ab5eaf70c096 (diff)
downloadrabbitmq-server-4456a1a46b36b472cc29641cee5fe7e15da5393a.tar.gz
one way to check whether rabbit is runningbug24377
and avoid timeouts in application:which_applications() in doing so
-rw-r--r--src/rabbit.erl15
-rw-r--r--src/rabbit_control.erl8
-rw-r--r--src/rabbit_direct.erl2
-rw-r--r--src/rabbit_upgrade.erl8
4 files changed, 16 insertions, 17 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 8cae7fde..b8dbccc7 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -18,7 +18,8 @@
-behaviour(application).
--export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0, environment/0,
+-export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0,
+ is_running/0 , is_running/1, environment/0,
rotate_logs/1, force_event_refresh/0]).
-export([start/2, stop/1]).
@@ -196,6 +197,8 @@
{os, {atom(), atom()}} |
{erlang_version, string()} |
{memory, any()}]).
+-spec(is_running/0 :: () -> boolean()).
+-spec(is_running/1 :: (node()) -> boolean()).
-spec(environment/0 :: () -> [{atom() | term()}]).
-spec(log_location/1 :: ('sasl' | 'kernel') -> log_location()).
@@ -233,11 +236,19 @@ stop_and_halt() ->
status() ->
[{pid, list_to_integer(os:getpid())},
- {running_applications, application:which_applications()},
+ {running_applications, application:which_applications(infinity)},
{os, os:type()},
{erlang_version, erlang:system_info(system_version)},
{memory, erlang:memory()}].
+is_running() -> is_running(node()).
+
+is_running(Node) ->
+ case rpc:call(Node, application, which_applications, [infinity]) of
+ {badrpc, _} -> false;
+ Apps -> proplists:is_defined(rabbit, Apps)
+ end.
+
environment() ->
lists:keysort(
1, [P || P = {K, _} <- application:get_all_env(rabbit),
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index b9e550c9..d920ca31 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -362,7 +362,7 @@ wait_for_application(Node, PidFile, Inform) ->
wait_for_application(Node, Pid) ->
case process_up(Pid) of
- true -> case node_up(Node) of
+ true -> case rabbit:is_running(Node) of
true -> ok;
false -> timer:sleep(1000),
wait_for_application(Node, Pid)
@@ -378,12 +378,6 @@ wait_and_read_pid_file(PidFile) ->
{error, _} = E -> exit({error, {could_not_read_pid, E}})
end.
-node_up(Node) ->
- case rpc_call(Node, application, which_applications, [infinity]) of
- {badrpc, _} -> false;
- Apps -> proplists:is_defined(rabbit, Apps)
- end.
-
% Test using some OS clunkiness since we shouldn't trust
% rpc:call(os, getpid, []) at this point
process_up(Pid) ->
diff --git a/src/rabbit_direct.erl b/src/rabbit_direct.erl
index 68afaf5d..6f9a4650 100644
--- a/src/rabbit_direct.erl
+++ b/src/rabbit_direct.erl
@@ -72,7 +72,7 @@ list() ->
%%----------------------------------------------------------------------------
connect(Username, VHost, Protocol, Pid, Infos) ->
- case lists:keymember(rabbit, 1, application:which_applications()) of
+ case rabbit:is_running() of
true ->
case rabbit_access_control:check_user_login(Username, []) of
{ok, User} ->
diff --git a/src/rabbit_upgrade.erl b/src/rabbit_upgrade.erl
index 9739f6b7..e7a302f8 100644
--- a/src/rabbit_upgrade.erl
+++ b/src/rabbit_upgrade.erl
@@ -228,13 +228,7 @@ secondary_upgrade(AllNodes) ->
ok.
nodes_running(Nodes) ->
- [N || N <- Nodes, node_running(N)].
-
-node_running(Node) ->
- case rpc:call(Node, application, which_applications, []) of
- {badrpc, _} -> false;
- Apps -> lists:keysearch(rabbit, 1, Apps) =/= false
- end.
+ [N || N <- Nodes, rabbit:is_running(N)].
%% -------------------------------------------------------------------