Merge pull request #11909 from emqx/bugfix-plugins

fix: emqx failed to start if plugin dir is removed by the user
This commit is contained in:
Xinyu Liu 2023-11-11 10:51:26 +08:00 committed by GitHub
commit 7bb3ca5519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -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]},

View File

@ -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;