Skip to content

Commit a5ce361

Browse files
committed
rabbit_prelaunch_conf: Load additional Cuttlefish configuration files
By default, in addition to `$RABBITMQ_CONFIG_FILE`, we also load all matching `$RABBITMQ_CONFIG_FILES`. It allows to split the configuration into many files for easier management. Here is the behavior in more details: * If `$RABBITMQ_CONFIG_FILES` is a directory, all files directly inside it are considered. * If `$RABBITMQ_CONFIG_FILES` is a glob pattern, all files matching the pattern are considered. * `$RABBITMQ_CONFIG_FILES` is only relevant when the main configuration is either missing (the file does not exist or is empty) or uses the Cuttlefish format. The default value of `$RABBITMQ_CONFIG_FILES` is: * `/etc/rabbitmq/conf.d/*.conf` on Unix * `%APPDATA%\RabbitMQ\conf.d\*.conf` on Windows [#171491267]
1 parent 84176a6 commit a5ce361

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

apps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,28 @@ setup(Context) ->
2020

2121
%% TODO: Check if directories/files are inside Mnesia dir.
2222

23-
%% TODO: Support glob patterns & directories in RABBITMQ_CONFIG_FILE.
24-
2523
ok = set_default_config(),
2624

25+
AdditionalConfigFiles = find_additional_config_files(Context),
2726
AdvancedConfigFile = find_actual_advanced_config_file(Context),
2827
State = case find_actual_main_config_file(Context) of
2928
{MainConfigFile, erlang} ->
29+
case AdditionalConfigFiles of
30+
[] ->
31+
ok;
32+
_ ->
33+
rabbit_log_prelaunch:notice(
34+
"The following additional configuration "
35+
"files are not loaded when the main "
36+
"configuration file uses the Erlang terms "
37+
"based format"),
38+
lists:foreach(
39+
fun(File) ->
40+
rabbit_log_prelaunch:notice(
41+
" - ~ts", [File])
42+
end,
43+
AdditionalConfigFiles)
44+
end,
3045
Config = load_erlang_term_based_config_file(
3146
MainConfigFile),
3247
Apps = [App || {App, _} <- Config],
@@ -35,7 +50,17 @@ setup(Context) ->
3550
config_files => [MainConfigFile],
3651
config_advanced_file => undefined};
3752
{MainConfigFile, cuttlefish} ->
38-
ConfigFiles = [MainConfigFile],
53+
ConfigFiles = [MainConfigFile | AdditionalConfigFiles],
54+
Config = load_cuttlefish_config_file(Context,
55+
ConfigFiles,
56+
AdvancedConfigFile),
57+
Apps = [App || {App, _} <- Config],
58+
decrypt_config(Apps),
59+
#{config_type => cuttlefish,
60+
config_files => ConfigFiles,
61+
config_advanced_file => AdvancedConfigFile};
62+
undefined when AdditionalConfigFiles =/= [] ->
63+
ConfigFiles = AdditionalConfigFiles,
3964
Config = load_cuttlefish_config_file(Context,
4065
ConfigFiles,
4166
AdvancedConfigFile),
@@ -133,6 +158,16 @@ find_actual_main_config_file(#{main_config_file := File}) ->
133158
end
134159
end.
135160

161+
find_additional_config_files(#{additional_config_files := Pattern})
162+
when Pattern =/= undefined ->
163+
Pattern1 = case filelib:is_dir(Pattern) of
164+
true -> filename:join(Pattern, "*");
165+
false -> Pattern
166+
end,
167+
lists:sort(filelib:wildcard(Pattern1));
168+
find_additional_config_files(_) ->
169+
[].
170+
136171
find_actual_advanced_config_file(#{advanced_config_file := File}) ->
137172
case filelib:is_regular(File) of
138173
true -> File;

0 commit comments

Comments
 (0)