diff options
| author | Alexey Lebedeff <alebedev@mirantis.com> | 2016-07-22 10:24:28 +0300 |
|---|---|---|
| committer | Alexey Lebedeff <alebedev@mirantis.com> | 2016-07-22 10:30:18 +0300 |
| commit | 37d4fc789d89a1ff981bd8d771013014b4d05147 (patch) | |
| tree | 6a8f9098e8ef9281663bf294789644e0ebea28a5 /src | |
| parent | 0c316fc3b6c135236fb0a267b31595dc5762f9eb (diff) | |
| download | rabbitmq-server-git-37d4fc789d89a1ff981bd8d771013014b4d05147.tar.gz | |
Fix longname-mode on hosts without detectable FQDN
Server startup and CLI tools fail in longnames-mode if erlang is not
able to determine host FQDN (with at least one dot in it).
E.g. this can happen when you want to assemble a cluster using only
IP-addresses, and you completely don't care about FQDNs.
And it was not possible to alleviate this situation using any options
from http://erlang.org/doc/apps/erts/inet_cfg.html
Fixes #890
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_cli.erl | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl index 6b35482217..c8f704dc15 100644 --- a/src/rabbit_cli.erl +++ b/src/rabbit_cli.erl @@ -147,7 +147,7 @@ main(ParseFun, DoFun, UsageMod) -> start_distribution_anon(0, LastError) -> {error, LastError}; start_distribution_anon(TriesLeft, _) -> - NameCandidate = list_to_atom(rabbit_misc:format("rabbitmq-cli-~2..0b", [rand_compat:uniform(100)])), + NameCandidate = generate_cli_node_name(), case net_kernel:start([NameCandidate, name_type()]) of {ok, _} = Result -> Result; @@ -155,7 +155,7 @@ start_distribution_anon(TriesLeft, _) -> start_distribution_anon(TriesLeft - 1, Reason) end. -%% Tries to start distribution with randonm name choosen from limited list of candidates - to +%% Tries to start distribution with random name choosen from limited list of candidates - to %% prevent atom table pollution on target nodes. start_distribution() -> rabbit_nodes:ensure_epmd(), @@ -171,6 +171,22 @@ name_type() -> _ -> shortnames end. +generate_cli_node_name() -> + Base = rabbit_misc:format("rabbitmq-cli-~2..0b", [rand_compat:uniform(100)]), + NameAsList = + case {name_type(), inet_db:res_option(domain)} of + {longnames, []} -> + %% Distribution will fail to start if it's unable to + %% determine FQDN of a node (with at least one dot in + %% a name). + %% CLI is always an initiator of connection, so it + %% doesn't matter if the name will not resolve. + Base ++ "@" ++ inet_db:gethostname() ++ ".no-domain"; + _ -> + Base + end, + list_to_atom(NameAsList). + usage(Mod) -> usage(Mod, ?EX_USAGE). |
