|
@@ -27,14 +27,18 @@
|
|
|
%% @doc Load all plugins when the broker started.
|
|
%% @doc Load all plugins when the broker started.
|
|
|
-spec(load() -> list() | {error, any()}).
|
|
-spec(load() -> list() | {error, any()}).
|
|
|
load() ->
|
|
load() ->
|
|
|
- case env(loaded_file) of
|
|
|
|
|
|
|
+ case emqttd:conf(plugins_loaded_file) of
|
|
|
{ok, File} ->
|
|
{ok, File} ->
|
|
|
|
|
+ ensure_file(File),
|
|
|
with_loaded_file(File, fun(Names) -> load_plugins(Names, false) end);
|
|
with_loaded_file(File, fun(Names) -> load_plugins(Names, false) end);
|
|
|
undefined ->
|
|
undefined ->
|
|
|
%% No plugins available
|
|
%% No plugins available
|
|
|
ignore
|
|
ignore
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
|
|
+ensure_file(File) ->
|
|
|
|
|
+ case filelib:is_file(File) of false -> write_loaded([]); true -> ok end.
|
|
|
|
|
+
|
|
|
with_loaded_file(File, SuccFun) ->
|
|
with_loaded_file(File, SuccFun) ->
|
|
|
case read_loaded(File) of
|
|
case read_loaded(File) of
|
|
|
{ok, Names} ->
|
|
{ok, Names} ->
|
|
@@ -56,7 +60,7 @@ load_plugins(Names, Persistent) ->
|
|
|
%% @doc Unload all plugins before broker stopped.
|
|
%% @doc Unload all plugins before broker stopped.
|
|
|
-spec(unload() -> list() | {error, any()}).
|
|
-spec(unload() -> list() | {error, any()}).
|
|
|
unload() ->
|
|
unload() ->
|
|
|
- case env(loaded_file) of
|
|
|
|
|
|
|
+ case emqttd:conf(plugins_loaded_file) of
|
|
|
{ok, File} ->
|
|
{ok, File} ->
|
|
|
with_loaded_file(File, fun stop_plugins/1);
|
|
with_loaded_file(File, fun stop_plugins/1);
|
|
|
undefined ->
|
|
undefined ->
|
|
@@ -70,9 +74,9 @@ stop_plugins(Names) ->
|
|
|
%% @doc List all available plugins
|
|
%% @doc List all available plugins
|
|
|
-spec(list() -> [mqtt_plugin()]).
|
|
-spec(list() -> [mqtt_plugin()]).
|
|
|
list() ->
|
|
list() ->
|
|
|
- case env(plugins_etc) of
|
|
|
|
|
|
|
+ case emqttd:conf(plugins_etc_dir) of
|
|
|
{ok, PluginsEtc} ->
|
|
{ok, PluginsEtc} ->
|
|
|
- CfgFiles = filelib:wildcard("*.config", PluginsEtc),
|
|
|
|
|
|
|
+ CfgFiles = filelib:wildcard("*.conf", PluginsEtc),
|
|
|
Plugins = [plugin(PluginsEtc, CfgFile) || CfgFile <- CfgFiles],
|
|
Plugins = [plugin(PluginsEtc, CfgFile) || CfgFile <- CfgFiles],
|
|
|
StartedApps = names(started_app),
|
|
StartedApps = names(started_app),
|
|
|
lists:map(fun(Plugin = #mqtt_plugin{name = Name}) ->
|
|
lists:map(fun(Plugin = #mqtt_plugin{name = Name}) ->
|
|
@@ -223,14 +227,15 @@ plugin_unloaded(Name, true) ->
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
read_loaded() ->
|
|
read_loaded() ->
|
|
|
- {ok, File} = env(loaded_file),
|
|
|
|
|
- read_loaded(File).
|
|
|
|
|
|
|
+ case emqttd:conf(plugins_loaded_file) of
|
|
|
|
|
+ {ok, File} -> read_loaded(File);
|
|
|
|
|
+ undefined -> {error, not_found}
|
|
|
|
|
+ end.
|
|
|
|
|
|
|
|
-read_loaded(File) ->
|
|
|
|
|
- file:consult(File).
|
|
|
|
|
|
|
+read_loaded(File) -> file:consult(File).
|
|
|
|
|
|
|
|
write_loaded(AppNames) ->
|
|
write_loaded(AppNames) ->
|
|
|
- {ok, File} = env(loaded_file),
|
|
|
|
|
|
|
+ {ok, File} = emqttd:conf(plugins_loaded_file),
|
|
|
case file:open(File, [binary, write]) of
|
|
case file:open(File, [binary, write]) of
|
|
|
{ok, Fd} ->
|
|
{ok, Fd} ->
|
|
|
lists:foreach(fun(Name) ->
|
|
lists:foreach(fun(Name) ->
|
|
@@ -241,16 +246,3 @@ write_loaded(AppNames) ->
|
|
|
{error, Error}
|
|
{error, Error}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-env(Name) ->
|
|
|
|
|
- case application:get_env(emqttd, plugins) of
|
|
|
|
|
- {ok, PluginsEnv} ->
|
|
|
|
|
- case proplists:get_value(Name, PluginsEnv) of
|
|
|
|
|
- undefined ->
|
|
|
|
|
- undefined;
|
|
|
|
|
- Val ->
|
|
|
|
|
- {ok, Val}
|
|
|
|
|
- end;
|
|
|
|
|
- undefined ->
|
|
|
|
|
- undefined
|
|
|
|
|
- end.
|
|
|
|
|
-
|
|
|