summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2019-08-12 21:55:15 +1000
committerMichael Klishin <mklishin@pivotal.io>2020-02-01 14:54:32 +0300
commita1ac3cde0c7815f0378f754815b06e04ebc6336c (patch)
treee22bf3313a93f2cb31552dde55e24f00877b472d
parent6ebf50b26f2eb6c2cac58ff368b367d263982845 (diff)
downloadrabbitmq-server-git-a1ac3cde0c7815f0378f754815b06e04ebc6336c.tar.gz
Make it possible to pre-configure cluster name via config
Per discussion with @gerhard. (cherry picked from commit 1aba6fa06b040ea888c37be123d003bcd3af15f0) Conflicts: src/rabbit.erl src/rabbit_nodes.erl
-rw-r--r--priv/schema/rabbit.schema8
-rw-r--r--src/rabbit.erl7
-rw-r--r--src/rabbit_nodes.erl25
3 files changed, 33 insertions, 7 deletions
diff --git a/priv/schema/rabbit.schema b/priv/schema/rabbit.schema
index 9a2a260bec..f2c51df8d7 100644
--- a/priv/schema/rabbit.schema
+++ b/priv/schema/rabbit.schema
@@ -383,7 +383,7 @@ end}.
{datatype, {enum, [distinguished_name, common_name]}}
]}.
-%% SSL handshake timeout, in milliseconds.
+%% TLS handshake timeout, in milliseconds.
%%
%% {ssl_handshake_timeout, 5000},
@@ -391,6 +391,12 @@ end}.
{datatype, integer}
]}.
+%% Cluster name
+
+{mapping, "cluster_name", "rabbit.cluster_name", [
+ {datatype, string}
+]}.
+
%% Default worker process pool size. Used to limit maximum concurrency rate
%% of certain operations, e.g. queue initialisation and recovery on node boot.
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 0009b28d8c..21d260230c 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -226,13 +226,18 @@
[{description, "ready to communicate with peers and clients"},
{requires, [core_initialized, recovery, routing_ready]}]}).
+-rabbit_boot_step({cluster_name,
+ [{description, "sets cluster name if configured"},
+ {mfa, {rabbit_nodes, boot, []}},
+ {requires, pre_flight}
+ ]}).
+
-rabbit_boot_step({os_signal_handler,
[{description, "registers an OS signal handler"},
{mfa, {rabbit_sup, start_restartable_child,
[rabbit_os_signal_handler]}},
{requires, pre_flight}]}).
->>>>>>> aa48d22d0... Merge pull request #2227 from rabbitmq/rabbitmq-server-2222
-rabbit_boot_step({direct_client,
[{description, "direct client"},
{mfa, {rabbit_direct, boot, []}},
diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl
index b363ed4f05..c59775198d 100644
--- a/src/rabbit_nodes.erl
+++ b/src/rabbit_nodes.erl
@@ -19,16 +19,18 @@
-export([names/1, diagnostics/1, make/1, parts/1, cookie_hash/0,
is_running/2, is_process_running/2,
- cluster_name/0, set_cluster_name/2, ensure_epmd/0,
+ cluster_name/0, set_cluster_name/1, set_cluster_name/2, ensure_epmd/0,
all_running/0, name_type/0, running_count/0,
- await_running_count/2]).
+ await_running_count/2,
+ boot/0]).
-include_lib("kernel/include/inet.hrl").
+-include_lib("rabbit_common/include/rabbit.hrl").
-define(SAMPLING_INTERVAL, 1000).
%%----------------------------------------------------------------------------
-%% Specs
+%% API
%%----------------------------------------------------------------------------
-spec names(string()) ->
@@ -38,12 +40,18 @@
-spec is_running(node(), atom()) -> boolean().
-spec is_process_running(node(), atom()) -> boolean().
-spec cluster_name() -> binary().
--spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'.
-spec all_running() -> [node()].
-spec running_count() -> integer().
-
%%----------------------------------------------------------------------------
+boot() ->
+ case application:get_env(rabbit, cluster_name) of
+ undefined -> ok;
+ {ok, Name} ->
+ rabbit_log:info("Setting cluster name to '~s' as configured", [Name]),
+ set_cluster_name(rabbit_data_coercion:to_binary(Name))
+ end.
+
name_type() ->
case os:getenv("RABBITMQ_USE_LONGNAME") of
"true" -> longnames;
@@ -80,6 +88,13 @@ cluster_name_default() ->
FQDN = rabbit_net:hostname(),
list_to_binary(atom_to_list(make({ID, FQDN}))).
+-spec set_cluster_name(binary()) -> 'ok'.
+
+set_cluster_name(Name) ->
+ set_cluster_name(Name, ?INTERNAL_USER).
+
+-spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'.
+
set_cluster_name(Name, Username) ->
%% Cluster name should be binary
BinaryName = rabbit_data_coercion:to_binary(Name),