Skip to content

Commit bd39027

Browse files
committed
Add support for $RABBITMQ_ERLANG_COOKIE env var
It is the equivalent of the content of the Erlang cookie file. Note this variable IS the cookie value, NOT the path to a cookie file. If it is set, it will take precedence over the content of the Erlang cookie file. Fixes docker-library/rabbitmq#508.
1 parent 46b8321 commit bd39027

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

deps/rabbit/apps/rabbitmq_prelaunch/src/rabbit_prelaunch_dist.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-module(rabbit_prelaunch_dist).
22

3+
-include_lib("eunit/include/eunit.hrl").
34
-include_lib("kernel/include/logger.hrl").
45

56
-include_lib("rabbit_common/include/logging.hrl").
@@ -33,7 +34,9 @@ setup(#{nodename := Node, nodename_type := NameType} = Context) ->
3334
end,
3435
ok.
3536

36-
do_setup(#{nodename := Node, nodename_type := NameType}) ->
37+
do_setup(#{nodename := Node,
38+
nodename_type := NameType,
39+
var_origins := Origins} = Config) ->
3740
?LOG_DEBUG(
3841
"Starting Erlang distribution",
3942
#{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
@@ -49,6 +52,19 @@ do_setup(#{nodename := Node, nodename_type := NameType}) ->
4952
{ok, _} = net_kernel:start([Node, NameType]),
5053
ok
5154
end,
55+
56+
%% Override the Erlang cookie if one was set in the environment.
57+
case maps:get(erlang_cookie, Origins, default) of
58+
environment ->
59+
?LOG_DEBUG(
60+
"Override Erlang cookie using the one set in the environment",
61+
#{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
62+
Cookie = maps:get(erlang_cookie, Config),
63+
?assert(is_atom(Cookie)),
64+
true = erlang:set_cookie(node(), Cookie);
65+
_ ->
66+
ok
67+
end,
5268
ok.
5369

5470
%% Check whether a node with the same name is already running

0 commit comments

Comments
 (0)