fix: observer load command crash when loading noexist module
This commit is contained in:
parent
0f07f678e7
commit
574dc2f243
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_modules, [
|
||||
{description, "EMQX Modules"},
|
||||
{vsn, "5.0.22"},
|
||||
{vsn, "5.0.23"},
|
||||
{modules, []},
|
||||
{applications, [kernel, stdlib, emqx, emqx_ctl]},
|
||||
{mod, {emqx_modules_app, []}},
|
||||
|
|
|
@ -40,10 +40,18 @@ cmd(["bin_leak"]) ->
|
|||
recon:bin_leak(100)
|
||||
);
|
||||
cmd(["load", Mod]) ->
|
||||
Module = list_to_existing_atom(Mod),
|
||||
Nodes = nodes(),
|
||||
Res = remote_load(Nodes, Module),
|
||||
emqx_ctl:print("Loaded ~p module on ~p: ~p~n", [Module, Nodes, Res]);
|
||||
case nodes() of
|
||||
[] ->
|
||||
emqx_ctl:print("No other nodes in the cluster~n");
|
||||
Nodes ->
|
||||
case emqx_utils:safe_to_existing_atom(Mod) of
|
||||
{ok, Module} ->
|
||||
Res = recon:remote_load(Nodes, Module),
|
||||
emqx_ctl:print("Loaded ~p module on ~p: ~p~n", [Module, Nodes, Res]);
|
||||
{error, Reason} ->
|
||||
emqx_ctl:print("Module(~s) not found: ~p~n", [Mod, Reason])
|
||||
end
|
||||
end;
|
||||
cmd(_) ->
|
||||
emqx_ctl:usage([
|
||||
{"observer status", "Start observer in the current console"},
|
||||
|
@ -51,12 +59,5 @@ cmd(_) ->
|
|||
"Force all processes to perform garbage collection "
|
||||
"and prints the top-100 processes that freed the "
|
||||
"biggest amount of binaries, potentially highlighting leaks."},
|
||||
{"observer load Mod", "Ensure a module is loaded in all EMQX nodes in the cluster"}
|
||||
{"observer load Mod", "Enhanced module synchronization across all cluster nodes"}
|
||||
]).
|
||||
|
||||
%% recon:remote_load/1 has a bug, when nodes() returns [], it is
|
||||
%% taken by recon as a node name.
|
||||
%% before OTP 23, the call returns a 'badrpc' tuple
|
||||
%% after OTP 23, it crashes with 'badarg' error
|
||||
remote_load([], _Module) -> ok;
|
||||
remote_load(Nodes, Module) -> recon:remote_load(Nodes, Module).
|
||||
|
|
Loading…
Reference in New Issue