Przeglądaj źródła

fix: emqx failed to start if plugin dir is removed by the user

Shawn 2 lat temu
rodzic
commit
e0f4a2014d

+ 1 - 1
apps/emqx_plugins/src/emqx_plugins.app.src

@@ -1,7 +1,7 @@
 %% -*- mode: erlang -*-
 {application, emqx_plugins, [
     {description, "EMQX Plugin Management"},
-    {vsn, "0.1.6"},
+    {vsn, "0.1.7"},
     {modules, []},
     {mod, {emqx_plugins_app, []}},
     {applications, [kernel, stdlib, emqx]},

+ 11 - 3
apps/emqx_plugins/src/emqx_plugins.erl

@@ -433,9 +433,16 @@ do_ensure_started(NameVsn) ->
     tryit(
         "start_plugins",
         fun() ->
-            ok = ensure_exists_and_installed(NameVsn),
-            Plugin = do_read_plugin(NameVsn),
-            ok = load_code_start_apps(NameVsn, Plugin)
+            case ensure_exists_and_installed(NameVsn) of
+                ok ->
+                    Plugin = do_read_plugin(NameVsn),
+                    ok = load_code_start_apps(NameVsn, Plugin);
+                {error, plugin_not_found} ->
+                    ?SLOG(error, #{
+                        msg => "plugin_not_found",
+                        name_vsn => NameVsn
+                    })
+            end
         end
     ).
 
@@ -665,6 +672,7 @@ do_load_plugin_app(AppName, Ebin) ->
     lists:foreach(
         fun(BeamFile) ->
             Module = list_to_atom(filename:basename(BeamFile, ".beam")),
+            _ = code:purge(Module),
             case code:load_file(Module) of
                 {module, _} ->
                     ok;