|
@@ -30,9 +30,6 @@
|
|
|
-author("Feng Lee <feng@emqtt.io>").
|
|
-author("Feng Lee <feng@emqtt.io>").
|
|
|
|
|
|
|
|
-include("emqttd.hrl").
|
|
-include("emqttd.hrl").
|
|
|
--include("emqttd_cli.hrl").
|
|
|
|
|
-
|
|
|
|
|
--export([cli/1]).
|
|
|
|
|
|
|
|
|
|
-export([load/0, unload/0]).
|
|
-export([load/0, unload/0]).
|
|
|
|
|
|
|
@@ -40,36 +37,6 @@
|
|
|
|
|
|
|
|
-export([list/0]).
|
|
-export([list/0]).
|
|
|
|
|
|
|
|
-%%------------------------------------------------------------------------------
|
|
|
|
|
-%% CLI callback
|
|
|
|
|
-%%------------------------------------------------------------------------------
|
|
|
|
|
-
|
|
|
|
|
-cli(["list"]) ->
|
|
|
|
|
- lists:foreach(fun(Plugin) -> print(Plugin) end, list());
|
|
|
|
|
-
|
|
|
|
|
-cli(["load", Name]) ->
|
|
|
|
|
- case load(list_to_atom(Name)) of
|
|
|
|
|
- {ok, StartedApps} -> ?PRINT("Start apps: ~p~nPlugin ~s loaded successfully.~n", [StartedApps, Name]);
|
|
|
|
|
- {error, Reason} -> ?PRINT("load plugin error: ~p~n", [Reason])
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
-cli(["unload", Name]) ->
|
|
|
|
|
- case emqttd_plugins:unload(list_to_atom(Name)) of
|
|
|
|
|
- ok ->
|
|
|
|
|
- ?PRINT("Plugin ~s unloaded successfully.~n", [Name]);
|
|
|
|
|
- {error, Reason} ->
|
|
|
|
|
- ?PRINT("unload plugin error: ~p~n", [Reason])
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
-cli(_) ->
|
|
|
|
|
- ?PRINT_CMD("plugins list", "#query loaded plugins"),
|
|
|
|
|
- ?PRINT_CMD("plugins load <Plugin>", "#load plugin"),
|
|
|
|
|
- ?PRINT_CMD("plugins unload <Plugin>", "#unload plugin").
|
|
|
|
|
-
|
|
|
|
|
-print(#mqtt_plugin{name = Name, version = Ver, descr = Descr, active = Active}) ->
|
|
|
|
|
- ?PRINT("Plugin(~s, version=~s, description=~s, active=~s)~n",
|
|
|
|
|
- [Name, Ver, Descr, Active]).
|
|
|
|
|
-
|
|
|
|
|
%%------------------------------------------------------------------------------
|
|
%%------------------------------------------------------------------------------
|
|
|
%% @doc Load all plugins when the broker started.
|
|
%% @doc Load all plugins when the broker started.
|
|
|
%% @end
|
|
%% @end
|
|
@@ -77,7 +44,6 @@ print(#mqtt_plugin{name = Name, version = Ver, descr = Descr, active = Active})
|
|
|
|
|
|
|
|
-spec load() -> list() | {error, any()}.
|
|
-spec load() -> list() | {error, any()}.
|
|
|
load() ->
|
|
load() ->
|
|
|
- emqttd_ctl:register_cmd(plugins, {?MODULE, cli}, []),
|
|
|
|
|
case env(loaded_file) of
|
|
case env(loaded_file) of
|
|
|
{ok, File} ->
|
|
{ok, File} ->
|
|
|
with_loaded_file(File, fun(Names) -> load_plugins(Names, false) end);
|
|
with_loaded_file(File, fun(Names) -> load_plugins(Names, false) end);
|