diff options
author | Emile Joubert <emile@rabbitmq.com> | 2010-12-07 12:48:58 +0000 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2010-12-07 12:48:58 +0000 |
commit | e279f44c444dc59e75f51b89ce140d0eb2dd2f6b (patch) | |
tree | d01c63747517ff4b89571beca72e86ef5c9d9d03 | |
parent | a500710672ea861eddd08bb09ae9e803e6767a7e (diff) | |
download | rabbitmq-server-e279f44c444dc59e75f51b89ce140d0eb2dd2f6b.tar.gz |
Perform duplicate node check in a function
-rw-r--r-- | src/rabbit_prelaunch.erl | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl index 79634352..0314cde5 100644 --- a/src/rabbit_prelaunch.erl +++ b/src/rabbit_prelaunch.erl @@ -132,27 +132,7 @@ start() -> || App <- PluginApps], io:nl(), - % check whether a node with the same name is already running - case Node of - [] -> ok; - _ -> {NodeName, NodeHost} = rabbit_misc:nodeparts(Node), - case net_adm:names(NodeHost) of - {ok, NamePorts} -> - case proplists:is_defined(NodeName, NamePorts) of - true -> io:format("node with name ~p " - "already running on ~p~n", - [NodeName, NodeHost]), - [io:format(Fmt ++ "~n", Args) || - {Fmt, Args} <- - rabbit_control:diagnostics(Node)], - terminate(?ERROR_CODE); - false -> ok - end; - {error, address} -> ok; - {error, EpmdReason} -> terminate("unexpected epmd error:~p~n", - [EpmdReason]) - end - end, + ok = duplicate_node_check(Node), terminate(0), ok. @@ -275,6 +255,32 @@ process_entry(Entry = {apply,{application,start_boot,[rabbit,permanent]}}) -> process_entry(Entry) -> [Entry]. +%% Check whether a node with the same name is already running +duplicate_node_check([]) -> + %% Ignore running node while installing windows service + ok; +duplicate_node_check(Node) -> + case Node of + [] -> ok; + _ -> {NodeName, NodeHost} = rabbit_misc:nodeparts(Node), + case net_adm:names(NodeHost) of + {ok, NamePorts} -> + case proplists:is_defined(NodeName, NamePorts) of + true -> io:format("node with name ~p " + "already running on ~p~n", + [NodeName, NodeHost]), + [io:format(Fmt ++ "~n", Args) || + {Fmt, Args} <- + rabbit_control:diagnostics(Node)], + terminate(?ERROR_CODE); + false -> ok + end; + {error, address} -> ok; + {error, EpmdReason} -> terminate("unexpected epmd error:~p~n", + [EpmdReason]) + end + end. + terminate(Fmt, Args) -> io:format("ERROR: " ++ Fmt ++ "~n", Args), terminate(?ERROR_CODE). |