summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2020-03-16 17:00:02 +0100
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2020-04-23 17:33:45 +0200
commit7edfe2292c3c59a8e03e37574b89a00708ae1bf8 (patch)
tree472980b0adac31a6dbf80b1fc5f49a0af4c82e4f /src
parentc9e9509846b85ce63f0588b937e7e01cdbd45df9 (diff)
downloadrabbitmq-server-git-7edfe2292c3c59a8e03e37574b89a00708ae1bf8.tar.gz
rabbit_prelaunch_conf: Always handle config. files with Cuttlefish
This has several benefits: 1. It simplifies the code, all configuration being handled by the same code path (no more condition on Erlang-term-based vs. Cuttlefish). `rabbit_config` shrinks quite a lot in the process. 2. We can use additional configuration files AND an Erlang-term-based configuration file. In other words, it is possible to use the same existing Erlang-term-based file and introduce Cuttlefish files when needed. It allows a user to run RabbitMQ with: RABBITMQ_CONFIG_FILE=/path/to/rabbitmq.config \ RABBITMQ_CONFIG_FILES=/path/to/conf.d/*.conf \ ./sbin/rabbitmq-server A developer can do the same with `make run-broker`: make run-broker \ RABBITMQ_CONFIG_FILES=/path/to/conf.d/*.conf In the example above, the main configuration file generated by rabbitmq-run.mk is an Erlang-term-based one. This is implemented by calling Cuttlefish with a (possibly empty) list of additional files and the Erlang-term-based file as the advanced configuration file. References #2180.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_config.erl66
1 files changed, 9 insertions, 57 deletions
diff --git a/src/rabbit_config.erl b/src/rabbit_config.erl
index 573a972c68..d65475d388 100644
--- a/src/rabbit_config.erl
+++ b/src/rabbit_config.erl
@@ -10,24 +10,10 @@
-type config_location() :: string().
-%% we support both the classic Erlang term
-%% config file (rabbitmq.config) as well as rabbitmq.conf
-legacy_erlang_term_config_used() ->
- case get_prelaunch_config_state() of
- #{config_type := erlang,
- config_advanced_file := undefined} ->
- true;
- _ ->
- false
- end.
-
get_confs() ->
case get_prelaunch_config_state() of
- #{config_files := Confs} ->
- [ filename:rootname(Conf, ".conf") ++ ".conf"
- || Conf <- Confs ];
- _ ->
- []
+ #{config_files := Confs} -> Confs;
+ _ -> []
end.
schema_dir() ->
@@ -43,7 +29,7 @@ schema_dir() ->
get_advanced_config() ->
case get_prelaunch_config_state() of
%% There can be only one advanced.config
- #{config_advanced_file := FileName} ->
+ #{config_advanced_file := FileName} when FileName =/= undefined ->
case rabbit_file:is_file(FileName) of
true -> FileName;
false -> none
@@ -53,47 +39,13 @@ get_advanced_config() ->
-spec config_files() -> [config_location()].
config_files() ->
- case legacy_erlang_term_config_used() of
- true ->
- case get_prelaunch_config_state() of
- #{config_files := Files} ->
- [ filename:absname(filename:rootname(File) ++ ".config")
- || File <- Files];
- _ ->
- case config_setting() of
+ ConfFiles = [filename:absname(File) || File <- get_confs(),
+ filelib:is_regular(File)],
+ AdvancedFiles = case get_advanced_config() of
none -> [];
- File -> [filename:absname(filename:rootname(File, ".config") ++ ".config")
- ++
- " (not found)"]
- end
- end;
- false ->
- ConfFiles = [filename:absname(File) || File <- get_confs(),
- filelib:is_regular(File)],
- AdvancedFiles = case get_advanced_config() of
- none -> [];
- FileName -> [filename:absname(FileName)]
- end,
- AdvancedFiles ++ ConfFiles
-
- end.
+ FileName -> [filename:absname(FileName)]
+ end,
+ AdvancedFiles ++ ConfFiles.
get_prelaunch_config_state() ->
rabbit_prelaunch_conf:get_config_state().
-
-%% This is a pain. We want to know where the config file is. But we
-%% can't specify it on the command line if it is missing or the VM
-%% will fail to start, so we need to find it by some mechanism other
-%% than init:get_arguments/0. We can look at the environment variable
-%% which is responsible for setting it... but that doesn't work for a
-%% Windows service since the variable can change and the service not
-%% be reinstalled, so in that case we add a magic application env.
-config_setting() ->
- case application:get_env(rabbit, windows_service_config) of
- {ok, File1} -> File1;
- undefined ->
- case application:get_env(rabbitmq_prelaunch, context) of
- #{main_config_file := File2} -> File2;
- _ -> none
- end
- end.