summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bakken <lbakken@pivotal.io>2019-12-18 09:41:20 -0800
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2019-12-19 13:59:18 +0100
commit027f68648648dbd25e8a329de5eaec574af4c529 (patch)
tree5e83c9858f95f36684cbbdd83af8b6eee9432c3f
parent2b4e0c8739407b13fca8e70c3c746933bb104bf4 (diff)
downloadrabbitmq-server-git-027f68648648dbd25e8a329de5eaec574af4c529.tar.gz
rabbitmq_prelaunch: Run rabbit_prelaunch_conf:setup/1 earlier
This fixes the issue where applications' configuration is applied after they are started (and they do not read their environment again after startup). This is the case of applications such as `ra` or `sysmon_handler`: they are dependencies of `rabbit` and the Erlang application controller will start them before. Now, the configuration is loaded during the first prelaunch phase by rabbitmq_prelaunch, hopefully before those applications are started. To permit this change, the code updating the `enabled_plugins_file` was moved to its own module. This one can't be moved to the rabbitmq_prelaunch application because it depends on `rabbit_plugins`. While here, add a couple assertions by checking return values.
-rw-r--r--apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl5
-rw-r--r--apps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl (renamed from src/rabbit_prelaunch_conf.erl)51
-rw-r--r--src/rabbit.erl13
-rw-r--r--src/rabbit_prelaunch_enabled_plugins_file.erl46
4 files changed, 61 insertions, 54 deletions
diff --git a/apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl b/apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl
index 5c3d56cd50..aba76c197c 100644
--- a/apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl
+++ b/apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl
@@ -105,7 +105,10 @@ do_run() ->
%% 2. Erlang distribution check + start.
ok = rabbit_prelaunch_dist:setup(Context),
- %% 3. Write PID file.
+ %% 3. Configuration check + loading.
+ ok = rabbit_prelaunch_conf:setup(Context),
+
+ %% 4. Write PID file.
rabbit_log_prelaunch:debug(""),
_ = write_pid_file(Context),
ignore.
diff --git a/src/rabbit_prelaunch_conf.erl b/apps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl
index 23d0f68f82..928cc45e14 100644
--- a/src/rabbit_prelaunch_conf.erl
+++ b/apps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl
@@ -23,9 +23,7 @@ setup(Context) ->
%% TODO: Support glob patterns & directories in RABBITMQ_CONFIG_FILE.
%% TODO: Always try parsing of both erlang and cuttlefish formats.
- update_enabled_plugins_file(Context),
-
- set_default_config(),
+ ok = set_default_config(),
AdvancedConfigFile = find_actual_advanced_config_file(Context),
State = case find_actual_main_config_file(Context) of
@@ -63,7 +61,7 @@ setup(Context) ->
config_files => [],
config_advanced_file => undefined}
end,
- override_with_hard_coded_critical_config(),
+ ok = override_with_hard_coded_critical_config(),
rabbit_log_prelaunch:debug(
"Saving config state to application env: ~p", [State]),
store_config_state(State).
@@ -75,49 +73,6 @@ get_config_state() ->
persistent_term:get({rabbitmq_prelaunch, config_state}, undefined).
%% -------------------------------------------------------------------
-%% `enabled_plugins` file content initialization.
-%% -------------------------------------------------------------------
-
-update_enabled_plugins_file(Context) ->
- %% We only do this on startup, not when the configuration is
- %% reloaded.
- case get_config_state() of
- undefined -> update_enabled_plugins_file1(Context);
- _ -> ok
- end.
-
-update_enabled_plugins_file1(#{enabled_plugins := undefined}) ->
- ok;
-update_enabled_plugins_file1(#{enabled_plugins := all,
- plugins_path := Path} = Context) ->
- List = [P#plugin.name || P <- rabbit_plugins:list(Path)],
- do_update_enabled_plugins_file(Context, List);
-update_enabled_plugins_file1(#{enabled_plugins := List} = Context) ->
- do_update_enabled_plugins_file(Context, List).
-
-do_update_enabled_plugins_file(#{enabled_plugins_file := File}, List) ->
- SortedList = lists:usort(List),
- case SortedList of
- [] ->
- rabbit_log_prelaunch:debug("Marking all plugins as disabled");
- _ ->
- rabbit_log_prelaunch:debug(
- "Marking the following plugins as enabled:"),
- [rabbit_log_prelaunch:debug(" - ~s", [P]) || P <- SortedList]
- end,
- Content = io_lib:format("~p.~n", [SortedList]),
- case file:write_file(File, Content) of
- ok ->
- ok;
- {error, Reason} ->
- rabbit_log_prelaunch:error(
- "Failed to update enabled plugins file \"~ts\" "
- "from $RABBITMQ_ENABLED_PLUGINS: ~ts",
- [File, file:format_error(Reason)]),
- throw({error, failed_to_update_enabled_plugins_file})
- end.
-
-%% -------------------------------------------------------------------
%% Configuration loading.
%% -------------------------------------------------------------------
@@ -393,7 +348,7 @@ apply_erlang_term_based_config([{_, []} | Rest]) ->
apply_erlang_term_based_config(Rest);
apply_erlang_term_based_config([{App, Vars} | Rest]) ->
rabbit_log_prelaunch:debug(" Applying configuration for '~s':", [App]),
- apply_app_env_vars(App, Vars),
+ ok = apply_app_env_vars(App, Vars),
apply_erlang_term_based_config(Rest);
apply_erlang_term_based_config([]) ->
ok.
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 41d4d89e17..992afadbf8 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -331,24 +331,27 @@ run_prelaunch_second_phase() ->
ok
end,
- %% 1. Feature flags registry.
+ %% 1. Enabled plugins file.
+ ok = rabbit_prelaunch_enabled_plugins_file:setup(Context),
+
+ %% 2. Feature flags registry.
ok = rabbit_prelaunch_feature_flags:setup(Context),
- %% 2. Configuration check + loading.
+ %% 3. Configuration check + loading.
ok = rabbit_prelaunch_conf:setup(Context),
- %% 3. Logging.
+ %% 4. Logging.
ok = rabbit_prelaunch_logging:setup(Context),
case IsInitialPass of
true ->
- %% 4. HiPE compilation.
+ %% 5. HiPE compilation.
ok = rabbit_prelaunch_hipe:setup(Context);
false ->
ok
end,
- %% 5. Clustering.
+ %% 6. Clustering.
ok = rabbit_prelaunch_cluster:setup(Context),
%% Start Mnesia now that everything is ready.
diff --git a/src/rabbit_prelaunch_enabled_plugins_file.erl b/src/rabbit_prelaunch_enabled_plugins_file.erl
new file mode 100644
index 0000000000..e201b52403
--- /dev/null
+++ b/src/rabbit_prelaunch_enabled_plugins_file.erl
@@ -0,0 +1,46 @@
+-module(rabbit_prelaunch_enabled_plugins_file).
+
+-include_lib("rabbit_common/include/rabbit.hrl").
+
+-export([setup/1]).
+
+setup(Context) ->
+ rabbit_log_prelaunch:debug(""),
+ rabbit_log_prelaunch:debug("== Enabled plugins file =="),
+ update_enabled_plugins_file(Context).
+
+%% -------------------------------------------------------------------
+%% `enabled_plugins` file content initialization.
+%% -------------------------------------------------------------------
+
+update_enabled_plugins_file(#{enabled_plugins := undefined}) ->
+ ok;
+update_enabled_plugins_file(#{enabled_plugins := all,
+ plugins_path := Path} = Context) ->
+ List = [P#plugin.name || P <- rabbit_plugins:list(Path)],
+ do_update_enabled_plugins_file(Context, List);
+update_enabled_plugins_file(#{enabled_plugins := List} = Context) ->
+ do_update_enabled_plugins_file(Context, List).
+
+do_update_enabled_plugins_file(#{enabled_plugins_file := File}, List) ->
+ SortedList = lists:usort(List),
+ case SortedList of
+ [] ->
+ rabbit_log_prelaunch:debug("Marking all plugins as disabled");
+ _ ->
+ rabbit_log_prelaunch:debug(
+ "Marking the following plugins as enabled:"),
+ [rabbit_log_prelaunch:debug(" - ~s", [P]) || P <- SortedList]
+ end,
+ Content = io_lib:format("~p.~n", [SortedList]),
+ case file:write_file(File, Content) of
+ ok ->
+ rabbit_log_prelaunch:debug("Wrote plugins file: ~ts", [File]),
+ ok;
+ {error, Reason} ->
+ rabbit_log_prelaunch:error(
+ "Failed to update enabled plugins file \"~ts\" "
+ "from $RABBITMQ_ENABLED_PLUGINS: ~ts",
+ [File, file:format_error(Reason)]),
+ throw({error, failed_to_update_enabled_plugins_file})
+ end.