emqttd_plugins:init/0
This commit is contained in:
parent
36ecbdc653
commit
2e9bc16136
|
@ -48,6 +48,7 @@ start(_StartType, _StartArgs) ->
|
||||||
start_servers(Sup),
|
start_servers(Sup),
|
||||||
emqttd_cli:load(),
|
emqttd_cli:load(),
|
||||||
load_all_mods(),
|
load_all_mods(),
|
||||||
|
emqttd_plugins:init(),
|
||||||
emqttd_plugins:load(),
|
emqttd_plugins:load(),
|
||||||
start_listeners(),
|
start_listeners(),
|
||||||
register(emqttd, self()),
|
register(emqttd, self()),
|
||||||
|
|
|
@ -18,12 +18,27 @@
|
||||||
|
|
||||||
-include("emqttd.hrl").
|
-include("emqttd.hrl").
|
||||||
|
|
||||||
|
-export([init/0]).
|
||||||
|
|
||||||
-export([load/0, unload/0]).
|
-export([load/0, unload/0]).
|
||||||
|
|
||||||
-export([load/1, unload/1]).
|
-export([load/1, unload/1]).
|
||||||
|
|
||||||
-export([list/0]).
|
-export([list/0]).
|
||||||
|
|
||||||
|
init() ->
|
||||||
|
case emqttd:conf(plugins_etc_dir) of
|
||||||
|
{ok, PluginsEtc} ->
|
||||||
|
CfgFiles = filelib:wildcard("*.conf", PluginsEtc),
|
||||||
|
lists:foreach(fun(CfgFile) ->
|
||||||
|
App = app_name(CfgFile),
|
||||||
|
application:set_env(App, conf, filename:join(PluginsEtc, CfgFile)),
|
||||||
|
gen_conf:init(App)
|
||||||
|
end, CfgFiles);
|
||||||
|
undefined ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
%% @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() ->
|
||||||
|
@ -90,11 +105,11 @@ list() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
plugin(CfgFile) ->
|
plugin(CfgFile) ->
|
||||||
[AppName | _] = string:tokens(CfgFile, "."),
|
AppName = app_name(CfgFile),
|
||||||
{ok, Attrs} = application:get_all_key(list_to_atom(AppName)),
|
{ok, Attrs} = application:get_all_key(AppName),
|
||||||
Ver = proplists:get_value(vsn, Attrs, "0"),
|
Ver = proplists:get_value(vsn, Attrs, "0"),
|
||||||
Descr = proplists:get_value(description, Attrs, ""),
|
Descr = proplists:get_value(description, Attrs, ""),
|
||||||
#mqtt_plugin{name = list_to_atom(AppName), version = Ver, descr = Descr}.
|
#mqtt_plugin{name = AppName, version = Ver, descr = Descr}.
|
||||||
|
|
||||||
%% @doc Load a Plugin
|
%% @doc Load a Plugin
|
||||||
-spec(load(atom()) -> ok | {error, any()}).
|
-spec(load(atom()) -> ok | {error, any()}).
|
||||||
|
@ -185,6 +200,9 @@ stop_app(App) ->
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
app_name(File) ->
|
||||||
|
[AppName | _] = string:tokens(File, "."), list_to_atom(AppName).
|
||||||
|
|
||||||
names(plugin) ->
|
names(plugin) ->
|
||||||
names(list());
|
names(list());
|
||||||
|
|
||||||
|
@ -244,4 +262,3 @@ write_loaded(AppNames) ->
|
||||||
lager:error("Open File ~p Error: ~p", [File, Error]),
|
lager:error("Open File ~p Error: ~p", [File, Error]),
|
||||||
{error, Error}
|
{error, Error}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue