Skip to content

Commit

Permalink
Merge emqx30 (#32)
Browse files Browse the repository at this point in the history
* Add 'plugins reload <Name>' CLI (#30)
  • Loading branch information
turtleDeng committed Jan 25, 2019
1 parent e3cbf0f commit 6f9998a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/emqx_mgmt_cli.erl
Expand Up @@ -327,6 +327,26 @@ plugins(["unload", Name]) ->
emqx_cli:print("unload plugin error: ~p~n", [Reason])
end;

plugins(["reload", Name]) ->
try
Plugin = list_to_existing_atom(Name),
Config = gen_config(Plugin),
case emqx_plugins:unload(Plugin) of
ok ->
lists:foreach(fun({Key, Val}) -> application:set_env(Plugin, Key, Val) end, Config),
case emqx_plugins:load(Plugin) of
{ok, _StartedApp} ->
emqx_cli:print("Plugin ~s reloaded successfully.~n", [Name]);
{error, Reason1} ->
emqx_cli:print("reload plugin error: ~p~n", [Reason1])
end;
{error, Reason} ->
emqx_cli:print("reload plugin error: ~p~n", [Reason])
end
catch _ : _Error : Stacktrace ->
emqx_cli:print("reload plugin error:~p~n", [Stacktrace])
end;

% plugins(["add", Name]) ->
% {ok, Path} = emqx:env(expand_plugins_dir),
% Dir = Path ++ Name,
Expand All @@ -344,7 +364,8 @@ plugins(["unload", Name]) ->
plugins(_) ->
emqx_cli:usage([{"plugins list", "Show loaded plugins"},
{"plugins load <Plugin>", "Load plugin"},
{"plugins unload <Plugin>", "Unload plugin"}
{"plugins unload <Plugin>", "Unload plugin"},
{"plugins reload <Plugin>", "Reload plugin"}
% {"plugins add <Plugin.zip>", "Add plugin"}
]).

Expand Down Expand Up @@ -771,3 +792,9 @@ format(_, Val) ->
Val.

bin(S) -> iolist_to_binary(S).

gen_config(App) ->
Schema = cuttlefish_schema:files([filename:join([code:priv_dir(App), App]) ++ ".schema"]),
Conf = cuttlefish_conf:file(filename:join([emqx_config:get_env(plugins_etc_dir), App] ++ ".conf")),
[{_, Config}] = cuttlefish_generator:map(Schema, Conf),
Config.

0 comments on commit 6f9998a

Please sign in to comment.