fix plugins code bug
This commit is contained in:
parent
c6ccacd990
commit
0f602d67ba
|
@ -184,14 +184,14 @@ plugins(["list"]) ->
|
||||||
|
|
||||||
plugins(["load", Name]) ->
|
plugins(["load", Name]) ->
|
||||||
case emqttd_plugins:load(list_to_atom(Name)) of
|
case emqttd_plugins:load(list_to_atom(Name)) of
|
||||||
{ok, StartedApps} -> ?PRINT("start apps: ~p, plugin ~s is loaded successfully.~n", [StartedApps, Name]);
|
{ok, StartedApps} -> ?PRINT("Start apps: ~p~nPlugin ~s loaded successfully.~n", [StartedApps, Name]);
|
||||||
{error, Reason} -> ?PRINT("load plugin error: ~s~n", [Reason])
|
{error, Reason} -> ?PRINT("load plugin error: ~p~n", [Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
plugins(["unload", Name]) ->
|
plugins(["unload", Name]) ->
|
||||||
case emqttd_plugins:unload(list_to_atom(Name)) of
|
case emqttd_plugins:unload(list_to_atom(Name)) of
|
||||||
ok -> ?PRINT("plugin ~s is unloaded successfully.~n", [Name]);
|
ok -> ?PRINT("Plugin ~s unloaded successfully.~n", [Name]);
|
||||||
{error, Reason} -> ?PRINT("unload plugin error: ~s~n", [Reason])
|
{error, Reason} -> ?PRINT("unload plugin error: ~p~n", [Reason])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
trace(["list"]) ->
|
trace(["list"]) ->
|
||||||
|
|
|
@ -157,6 +157,8 @@ load_app(App, Config) ->
|
||||||
case application:load(App) of
|
case application:load(App) of
|
||||||
ok ->
|
ok ->
|
||||||
set_config(Config);
|
set_config(Config);
|
||||||
|
{error, {already_loaded, App}} ->
|
||||||
|
set_config(Config);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
{error, Error}
|
{error, Error}
|
||||||
end.
|
end.
|
||||||
|
@ -241,7 +243,7 @@ plugin_loaded(Name, true) ->
|
||||||
case lists:member(Name, Names) of
|
case lists:member(Name, Names) of
|
||||||
false ->
|
false ->
|
||||||
%% write file if plugin is loaded
|
%% write file if plugin is loaded
|
||||||
write_loaded(lists:append(Names, Name));
|
write_loaded(lists:append(Names, [Name]));
|
||||||
true ->
|
true ->
|
||||||
ignore
|
ignore
|
||||||
end;
|
end;
|
||||||
|
@ -272,12 +274,14 @@ read_loaded(File) ->
|
||||||
file:consult(File).
|
file:consult(File).
|
||||||
|
|
||||||
write_loaded(AppNames) ->
|
write_loaded(AppNames) ->
|
||||||
case file:open(env(loaded_file), [binary, write]) of
|
{ok, File} = env(loaded_file),
|
||||||
|
case file:open(File, [binary, write]) of
|
||||||
{ok, Fd} ->
|
{ok, Fd} ->
|
||||||
lists:foreach(fun(Name) ->
|
lists:foreach(fun(Name) ->
|
||||||
file:write(Fd, iolist_to_binary(io_lib:format("~s.~n", [Name])))
|
file:write(Fd, iolist_to_binary(io_lib:format("~s.~n", [Name])))
|
||||||
end, AppNames);
|
end, AppNames);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
|
lager:error("Open File ~p Error: ~p", [File, Error]),
|
||||||
{error, Error}
|
{error, Error}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue