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 | 9900fdc699326669979385c8a812c6ba3dd0091c (patch) | |
| tree | d01c63747517ff4b89571beca72e86ef5c9d9d03 | |
| parent | 1c60674660cb83ff8a8b9cbab61ea072309626da (diff) | |
| download | rabbitmq-server-git-9900fdc699326669979385c8a812c6ba3dd0091c.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 796343522c..0314cde5f8 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). |
