Просмотр исходного кода

fix: mark fresh install to cp the default configuration file directly

JimMoen 1 год назад
Родитель
Сommit
19e039e0d2

+ 1 - 1
apps/emqx_management/src/emqx_mgmt_api_plugins.erl

@@ -59,7 +59,6 @@
 -define(VSN_WILDCARD, "-*.tar.gz").
 
 -define(CONTENT_PLUGIN, plugin).
--define(CONTENT_CONFIG, config).
 
 namespace() ->
     "plugins".
@@ -565,6 +564,7 @@ install_package(FileName, Bin) ->
     ok = filelib:ensure_dir(File),
     ok = file:write_file(File, Bin),
     PackageName = string:trim(FileName, trailing, ".tar.gz"),
+    put(?fresh_install, true),
     case emqx_plugins:ensure_installed(PackageName) of
         {error, #{reason := not_found}} = NotFound ->
             NotFound;

+ 1 - 0
apps/emqx_plugins/include/emqx_plugins.hrl

@@ -26,6 +26,7 @@
 
 -define(plugin_conf_not_found, plugin_conf_not_found).
 -define(plugin_without_config_schema, plugin_without_config_schema).
+-define(fresh_install, fresh_install).
 
 -type schema_name() :: binary().
 -type avsc_path() :: string().

+ 12 - 5
apps/emqx_plugins/src/emqx_plugins.erl

@@ -1233,9 +1233,18 @@ maybe_ensure_plugin_config(NameVsn) ->
 
 -spec ensure_plugin_config(name_vsn()) -> ok.
 ensure_plugin_config(NameVsn) ->
-    %% fetch plugin hocon config from cluster
-    Nodes = [N || N <- mria:running_nodes(), N /= node()],
-    ensure_plugin_config(NameVsn, Nodes).
+    case get(?fresh_install) of
+        true ->
+            ?SLOG(debug, #{
+                msg => "default_plugin_config_used",
+                name_vsn => NameVsn,
+                reason => "fresh_install"
+            }),
+            cp_default_config_file(NameVsn);
+        _ ->
+            %% fetch plugin hocon config from cluster
+            ensure_plugin_config(NameVsn, [N || N <- mria:running_nodes(), N /= node()])
+    end.
 
 -spec ensure_plugin_config(name_vsn(), list()) -> ok.
 ensure_plugin_config(NameVsn, []) ->
@@ -1255,8 +1264,6 @@ ensure_plugin_config(NameVsn, Nodes) ->
             ensure_config_map(NameVsn);
         _ ->
             ?SLOG(error, #{msg => "config_not_found_from_cluster", name_vsn => NameVsn}),
-            %% otherwise cp default hocon file
-            %% i.e. Clean installation
             cp_default_config_file(NameVsn)
     end.