Skip to content

Commit

Permalink
Add support for $RABBITMQ_ERLANG_COOKIE env var
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dumbbell committed Aug 11, 2021
1 parent f0f3527 commit 5b99759
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-module(rabbit_prelaunch_dist).

-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/logger.hrl").

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

do_setup(#{nodename := Node, nodename_type := NameType}) ->
do_setup(#{nodename := Node,
nodename_type := NameType,
var_origins := Origins} = Config) ->
?LOG_DEBUG(
"Starting Erlang distribution",
#{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
Expand All @@ -49,6 +52,19 @@ do_setup(#{nodename := Node, nodename_type := NameType}) ->
{ok, _} = net_kernel:start([Node, NameType]),
ok
end,

%% Override the Erlang cookie if one was set in the environment.
case maps:get(erlang_cookie, Origins, default) of
environment ->
?LOG_DEBUG(
"Override Erlang cookie using the one set in the environment",
#{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
Cookie = maps:get(erlang_cookie, Config),
?assert(is_atom(Cookie)),
true = erlang:set_cookie(node(), Cookie);
_ ->
ok
end,
ok.

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

0 comments on commit 5b99759

Please sign in to comment.