diff options
| -rw-r--r-- | priv/schema/rabbitmq.schema | 21 | ||||
| -rwxr-xr-x | scripts/rabbitmq-server | 13 | ||||
| -rw-r--r-- | src/rabbit_cli.erl | 20 | ||||
| -rw-r--r-- | test/config_schema_SUITE_data/schema/rabbitmq.schema | 21 | ||||
| -rw-r--r-- | test/config_schema_SUITE_data/schema/rabbitmq_mqtt.schema | 13 | ||||
| -rw-r--r-- | test/config_schema_SUITE_data/snippets.config | 20 |
6 files changed, 102 insertions, 6 deletions
diff --git a/priv/schema/rabbitmq.schema b/priv/schema/rabbitmq.schema index 19040da409..bf9cccbcb8 100644 --- a/priv/schema/rabbitmq.schema +++ b/priv/schema/rabbitmq.schema @@ -522,7 +522,7 @@ end}. {translation, "rabbit.tcp_listen_options", fun(Conf) -> - case cuttlefish:conf_get("tcp_listen_options", undefined) of + case cuttlefish:conf_get("tcp_listen_options", Conf, undefined) of none -> []; _ -> cuttlefish:invalid("Invalid tcp_listen_options") end @@ -587,6 +587,20 @@ end}. {mapping, "tcp_listen_options.tos", "rabbit.tcp_listen_options.tos", [{datatype, integer}]}. +{mapping, "tcp_listen_options.linger.on", "rabbit.tcp_listen_options.linger", + [{datatype, {enum, [true, false]}}]}. + +{mapping, "tcp_listen_options.linger.timeout", "rabbit.tcp_listen_options.linger", + [{datatype, integer}, {validators, ["non_negative_integer"]}]}. + +{translation, "rabbit.tcp_listen_options.linger", +fun(Conf) -> + LingerOn = cuttlefish:conf_get("tcp_listen_options.linger.on", Conf, false), + LingerTimeout = cuttlefish:conf_get("tcp_listen_options.linger.timeout", Conf, 0), + {LingerOn, LingerTimeout} +end}. + + %% ========================================================================== %% @@ -959,3 +973,8 @@ fun(IpStr) -> Res = inet:parse_address(IpStr), element(1, Res) == ok end}. + +{validator, "non_negative_integer", "number should be greater or equal to zero", +fun(Int) when is_integer(Int) -> + Int >= 0 +end}. diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index 6d82588ee2..a0500ebb87 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -67,6 +67,17 @@ if [ "${RABBITMQ_ADVANCED_CONFIG_FILE_NOEX}.config" = "${RABBITMQ_ADVANCED_CONFI RABBITMQ_ADVANCED_CONFIG_FILE="${RABBITMQ_ADVANCED_CONFIG_FILE_NOEX}" fi +# `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= \ @@ -77,7 +88,7 @@ RABBITMQ_DIST_PORT=$RABBITMQ_DIST_PORT \ -noinput \ -hidden \ -s rabbit_prelaunch \ - ${RABBITMQ_NAME_TYPE} rabbitmqprelaunch$$ \ + ${RABBITMQ_NAME_TYPE} ${RABBITMQ_PRELAUNCH_NODENAME} \ -conf_advanced "${RABBITMQ_ADVANCED_CONFIG_FILE}" \ -rabbit enabled_plugins_file "\"$RABBITMQ_ENABLED_PLUGINS_FILE\"" \ -rabbit plugins_dir "\"$RABBITMQ_PLUGINS_DIR\"" \ diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl index d324625d1b..862725f550 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: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: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). diff --git a/test/config_schema_SUITE_data/schema/rabbitmq.schema b/test/config_schema_SUITE_data/schema/rabbitmq.schema index 19040da409..bf9cccbcb8 100644 --- a/test/config_schema_SUITE_data/schema/rabbitmq.schema +++ b/test/config_schema_SUITE_data/schema/rabbitmq.schema @@ -522,7 +522,7 @@ end}. {translation, "rabbit.tcp_listen_options", fun(Conf) -> - case cuttlefish:conf_get("tcp_listen_options", undefined) of + case cuttlefish:conf_get("tcp_listen_options", Conf, undefined) of none -> []; _ -> cuttlefish:invalid("Invalid tcp_listen_options") end @@ -587,6 +587,20 @@ end}. {mapping, "tcp_listen_options.tos", "rabbit.tcp_listen_options.tos", [{datatype, integer}]}. +{mapping, "tcp_listen_options.linger.on", "rabbit.tcp_listen_options.linger", + [{datatype, {enum, [true, false]}}]}. + +{mapping, "tcp_listen_options.linger.timeout", "rabbit.tcp_listen_options.linger", + [{datatype, integer}, {validators, ["non_negative_integer"]}]}. + +{translation, "rabbit.tcp_listen_options.linger", +fun(Conf) -> + LingerOn = cuttlefish:conf_get("tcp_listen_options.linger.on", Conf, false), + LingerTimeout = cuttlefish:conf_get("tcp_listen_options.linger.timeout", Conf, 0), + {LingerOn, LingerTimeout} +end}. + + %% ========================================================================== %% @@ -959,3 +973,8 @@ fun(IpStr) -> Res = inet:parse_address(IpStr), element(1, Res) == ok end}. + +{validator, "non_negative_integer", "number should be greater or equal to zero", +fun(Int) when is_integer(Int) -> + Int >= 0 +end}. diff --git a/test/config_schema_SUITE_data/schema/rabbitmq_mqtt.schema b/test/config_schema_SUITE_data/schema/rabbitmq_mqtt.schema index 1daab5423d..ffda10beaa 100644 --- a/test/config_schema_SUITE_data/schema/rabbitmq_mqtt.schema +++ b/test/config_schema_SUITE_data/schema/rabbitmq_mqtt.schema @@ -233,3 +233,16 @@ end}. {mapping, "mqtt.tcp_listen_options.tos", "rabbitmq_mqtt.tcp_listen_options.tos", [{datatype, integer}]}. + +{mapping, "mqtt.tcp_listen_options.linger.on", "rabbitmq_mqtt.tcp_listen_options.linger", + [{datatype, {enum, [true, false]}}]}. + +{mapping, "mqtt.tcp_listen_options.linger.timeout", "rabbitmq_mqtt.tcp_listen_options.linger", + [{datatype, integer}]}. + +{translation, "rabbitmq_mqtt.tcp_listen_options.linger", +fun(Conf) -> + LingerOn = cuttlefish:conf_get("mqtt.tcp_listen_options.linger.on", Conf, false), + LingerTimeout = cuttlefish:conf_get("mqtt.tcp_listen_options.linger.timeout", Conf, 0), + {LingerOn, LingerTimeout} +end}. diff --git a/test/config_schema_SUITE_data/snippets.config b/test/config_schema_SUITE_data/snippets.config index 22c9f2b7cd..abfc28441e 100644 --- a/test/config_schema_SUITE_data/snippets.config +++ b/test/config_schema_SUITE_data/snippets.config @@ -710,5 +710,23 @@ rabbitmq_auth_backend_http.resource_path = http://some-server/auth/resource", [{user_path, "http://some-server/auth/user"}, {vhost_path, "http://some-server/auth/vhost"}, {resource_path, "http://some-server/auth/resource"}]}], -[rabbitmq_auth_backend_http]} +[rabbitmq_auth_backend_http]}, +{70, +"tcp_listen_options.linger.on = true +tcp_listen_options.linger.timeout = 100", +[{rabbit, [{tcp_listen_options, [{linger, {true, 100}}]}]}], +[]}, +{72, +"tcp_listen_options.linger.on = false +tcp_listen_options.linger.timeout = 100", +[{rabbit, [{tcp_listen_options, [{linger, {false, 100}}]}]}], +[]}, +{73, +"tcp_listen_options.linger.on = true", +[{rabbit, [{tcp_listen_options, [{linger, {true, 0}}]}]}], +[]}, +{74, +"tcp_listen_options.linger.timeout = 100", +[{rabbit, [{tcp_listen_options, [{linger, {false, 100}}]}]}], +[]} ]. |
