fix: unset config_loader in emqx's env when stop emqx app

This commit is contained in:
zhongwencool 2023-07-10 11:06:08 +08:00
parent 82672ff095
commit c4ba558ee3
6 changed files with 18 additions and 14 deletions

View File

@ -25,7 +25,9 @@
get_description/0, get_description/0,
get_release/0, get_release/0,
set_config_loader/1, set_config_loader/1,
get_config_loader/0 get_config_loader/0,
unset_config_loaded/0,
init_load_done/0
]). ]).
-include("logger.hrl"). -include("logger.hrl").
@ -54,14 +56,22 @@ prep_stop(_State) ->
stop(_State) -> ok. stop(_State) -> ok.
-define(CONFIG_LOADER, config_loader).
-define(DEFAULT_LOADER, emqx).
%% @doc Call this function to make emqx boot without loading config, %% @doc Call this function to make emqx boot without loading config,
%% in case we want to delegate the config load to a higher level app %% in case we want to delegate the config load to a higher level app
%% which manages emqx app. %% which manages emqx app.
set_config_loader(Module) when is_atom(Module) -> set_config_loader(Module) when is_atom(Module) ->
application:set_env(emqx, config_loader, Module). application:set_env(emqx, ?CONFIG_LOADER, Module).
get_config_loader() -> get_config_loader() ->
application:get_env(emqx, config_loader, emqx). application:get_env(emqx, ?CONFIG_LOADER, ?DEFAULT_LOADER).
unset_config_loaded() ->
application:unset_env(emqx, ?CONFIG_LOADER).
init_load_done() ->
get_config_loader() =/= ?DEFAULT_LOADER.
maybe_load_config() -> maybe_load_config() ->
case get_config_loader() of case get_config_loader() of

View File

@ -96,7 +96,7 @@ format_list(Listener) ->
do_list_raw() -> do_list_raw() ->
%% GET /listeners from other nodes returns [] when init config is not loaded. %% GET /listeners from other nodes returns [] when init config is not loaded.
case emqx_app:get_config_loader() =/= emqx of case emqx_app:init_load_done() of
true -> true ->
Key = <<"listeners">>, Key = <<"listeners">>,
Raw = emqx_config:get_raw([Key], #{}), Raw = emqx_config:get_raw([Key], #{}),

View File

@ -22,9 +22,6 @@
-export([get_override_config_file/0]). -export([get_override_config_file/0]).
-export([sync_data_from_node/0]). -export([sync_data_from_node/0]).
%% Test purposes
-export([init_load_done/0]).
-include_lib("emqx/include/logger.hrl"). -include_lib("emqx/include/logger.hrl").
-include("emqx_conf.hrl"). -include("emqx_conf.hrl").
@ -49,7 +46,7 @@ stop(_State) ->
%% This function is named 'override' due to historical reasons. %% This function is named 'override' due to historical reasons.
get_override_config_file() -> get_override_config_file() ->
Node = node(), Node = node(),
case init_load_done() of case emqx_app:init_load_done() of
false -> false ->
{error, #{node => Node, msg => "init_conf_load_not_done"}}; {error, #{node => Node, msg => "init_conf_load_not_done"}};
true -> true ->
@ -109,10 +106,6 @@ init_load(TnxId) ->
}) })
end. end.
init_load_done() ->
% NOTE: Either us or some higher level (i.e. tests) code loaded config.
emqx_app:get_config_loader() =/= emqx.
init_conf() -> init_conf() ->
emqx_cluster_rpc:wait_for_cluster_rpc(), emqx_cluster_rpc:wait_for_cluster_rpc(),
{ok, TnxId} = sync_cluster_conf(), {ok, TnxId} = sync_cluster_conf(),

View File

@ -215,7 +215,7 @@ assert_no_cluster_conf_copied([Node | Nodes], File) ->
assert_config_load_done(Nodes) -> assert_config_load_done(Nodes) ->
lists:foreach( lists:foreach(
fun(Node) -> fun(Node) ->
Done = rpc:call(Node, emqx_conf_app, init_load_done, []), Done = rpc:call(Node, emqx_app, init_load_done, []),
?assert(Done, #{node => Node}) ?assert(Done, #{node => Node})
end, end,
Nodes Nodes

View File

@ -3,7 +3,7 @@
{id, "emqx_machine"}, {id, "emqx_machine"},
{description, "The EMQX Machine"}, {description, "The EMQX Machine"},
% strict semver, bump manually! % strict semver, bump manually!
{vsn, "0.2.7"}, {vsn, "0.2.8"},
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{applications, [kernel, stdlib, emqx_ctl]}, {applications, [kernel, stdlib, emqx_ctl]},

View File

@ -61,6 +61,7 @@ start_autocluster() ->
stop_apps() -> stop_apps() ->
?SLOG(notice, #{msg => "stopping_emqx_apps"}), ?SLOG(notice, #{msg => "stopping_emqx_apps"}),
_ = emqx_alarm_handler:unload(), _ = emqx_alarm_handler:unload(),
ok = emqx_app:unset_config_loaded(),
lists:foreach(fun stop_one_app/1, lists:reverse(sorted_reboot_apps())). lists:foreach(fun stop_one_app/1, lists:reverse(sorted_reboot_apps())).
%% Those port apps are terminated after the main apps %% Those port apps are terminated after the main apps