diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-03-13 15:52:45 +0000 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-03-13 15:52:45 +0000 |
| commit | d84937fc9b103d82df3e2dd972321c6111a3c011 (patch) | |
| tree | 843edf26ddb988655014b220c67034268fb62570 | |
| parent | 0f410206ae6bd47acd9f71644eb04f78d3d13b7a (diff) | |
| download | rabbitmq-server-git-d84937fc9b103d82df3e2dd972321c6111a3c011.tar.gz | |
More robustness
| -rw-r--r-- | src/rabbit_prelaunch.erl | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl index 5068d24452..b8f9bfedb4 100644 --- a/src/rabbit_prelaunch.erl +++ b/src/rabbit_prelaunch.erl @@ -18,6 +18,8 @@ -export([start/0, stop/0]). +-import(rabbit_misc, [pget/2, pget/3]). + -include("rabbit.hrl"). -define(DIST_PORT_NOT_CONFIGURED, 0). @@ -74,25 +76,33 @@ duplicate_node_check(NodeStr) -> end. dist_port_set_check() -> - case file:consult(os:getenv("RABBITMQ_CONFIG_FILE") ++ ".config") of - {ok, [Config]} -> - Kernel = proplists:get_value(kernel, Config, []), - case {proplists:get_value(inet_dist_listen_min, Kernel, none), - proplists:get_value(inet_dist_listen_max, Kernel, none)} of - {none, none} -> ok; - _ -> rabbit_misc:quit(?DIST_PORT_CONFIGURED) - end; - {error, _} -> - %% TODO can we present errors more nicely here - %% than after -config has failed? - ok + case os:getenv("RABBITMQ_CONFIG_FILE") of + false -> + ok; + File -> + case file:consult(File ++ ".config") of + {ok, [Config]} -> + Kernel = pget(kernel, Config, []), + case {pget(inet_dist_listen_min, Kernel, none), + pget(inet_dist_listen_max, Kernel, none)} of + {none, none} -> ok; + _ -> rabbit_misc:quit(?DIST_PORT_CONFIGURED) + end; + {error, _} -> + %% TODO can we present errors more nicely here + %% than after -config has failed? + ok + end end. dist_port_use_check(NodeHost) -> - Port = list_to_integer(os:getenv("RABBITMQ_DIST_PORT")), - case gen_tcp:listen(Port, [inet]) of - {ok, Sock} -> gen_tcp:close(Sock); - {error, _} -> dist_port_use_check_fail(Port, NodeHost) + case os:getenv("RABBITMQ_DIST_PORT") of + false -> ok; + PortStr -> Port = list_to_integer(PortStr), + case gen_tcp:listen(Port, [inet]) of + {ok, Sock} -> gen_tcp:close(Sock); + {error, _} -> dist_port_use_check_fail(Port, NodeHost) + end end. dist_port_use_check_fail(Port, Host) -> |
