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 | |
| 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
| -rwxr-xr-x | scripts/rabbitmq-server | 13 | ||||
| -rw-r--r-- | src/rabbit_cli.erl | 20 |
2 files changed, 30 insertions, 3 deletions
diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index 74337311cd..c99022fcf6 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -62,6 +62,17 @@ RABBITMQ_EBIN_ROOT="${RABBITMQ_HOME}/ebin" set +e +# `net_kernel:start/1` will fail in `longnames` mode when erlang is +# unable to determine FQDN of a node (with a dot in it). But `erl` +# itself has some magic that still allow it to start when you +# explicitly specify host (a.la `erl -name test@localhost`). +# +# It's not possible to communicate with this node, unless it's a +# connection initiator. But as prelaunch IS an initiator, it doesn't +# matter what we actually put here. But `localhost` sounds good +# enough. +RABBITMQ_PRELAUNCH_NODENAME="rabbitmqprelaunch${$}@localhost" + # NOTIFY_SOCKET is needed here to prevent epmd from impersonating the # success of our startup sequence to systemd. NOTIFY_SOCKET= \ @@ -72,7 +83,7 @@ RABBITMQ_DIST_PORT=$RABBITMQ_DIST_PORT \ -noinput \ -hidden \ -s rabbit_prelaunch \ - ${RABBITMQ_NAME_TYPE} rabbitmqprelaunch$$ \ + ${RABBITMQ_NAME_TYPE} ${RABBITMQ_PRELAUNCH_NODENAME} \ -extra "${RABBITMQ_NODENAME}" PRELAUNCH_RESULT=$? 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). |
