Get the plugins list through -emqx_plugin module attributes
This commit is contained in:
parent
b79bf13ae7
commit
865ef864db
|
|
@ -60,14 +60,15 @@ load() ->
|
||||||
load_expand_plugins() ->
|
load_expand_plugins() ->
|
||||||
case emqx_config:get_env(expand_plugins_dir) of
|
case emqx_config:get_env(expand_plugins_dir) of
|
||||||
undefined -> ok;
|
undefined -> ok;
|
||||||
Dir ->
|
ExpandPluginsDir ->
|
||||||
PluginsDir = filelib:wildcard("*", Dir),
|
Plugins = filelib:wildcard("*", ExpandPluginsDir),
|
||||||
lists:foreach(fun(PluginDir) ->
|
lists:foreach(fun(Plugin) ->
|
||||||
case filelib:is_dir(Dir ++ PluginDir) of
|
PluginDir = filename:join(ExpandPluginsDir, Plugin),
|
||||||
true -> load_expand_plugin(Dir ++ PluginDir);
|
case filelib:is_dir(PluginDir) of
|
||||||
|
true -> load_expand_plugin(PluginDir);
|
||||||
false -> ok
|
false -> ok
|
||||||
end
|
end
|
||||||
end, PluginsDir)
|
end, Plugins)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
load_expand_plugin(PluginDir) ->
|
load_expand_plugin(PluginDir) ->
|
||||||
|
|
@ -98,25 +99,6 @@ init_expand_plugin_config(PluginDir) ->
|
||||||
[application:set_env(AppName, Par, Val) || {Par, Val} <- Envs]
|
[application:set_env(AppName, Par, Val) || {Par, Val} <- Envs]
|
||||||
end, AppsEnv).
|
end, AppsEnv).
|
||||||
|
|
||||||
get_expand_plugin_config() ->
|
|
||||||
case emqx_config:get_env(expand_plugins_dir) of
|
|
||||||
undefined -> ok;
|
|
||||||
Dir ->
|
|
||||||
PluginsDir = filelib:wildcard("*", Dir),
|
|
||||||
lists:foldl(fun(PluginDir, Acc) ->
|
|
||||||
case filelib:is_dir(Dir ++ PluginDir) of
|
|
||||||
true ->
|
|
||||||
Etc = Dir ++ PluginDir ++ "/etc",
|
|
||||||
case filelib:wildcard("*.{conf,config}", Etc) of
|
|
||||||
[] -> Acc;
|
|
||||||
[Conf] -> [Conf | Acc]
|
|
||||||
end;
|
|
||||||
false ->
|
|
||||||
Acc
|
|
||||||
end
|
|
||||||
end, [], PluginsDir)
|
|
||||||
end.
|
|
||||||
|
|
||||||
ensure_file(File) ->
|
ensure_file(File) ->
|
||||||
case filelib:is_file(File) of false -> write_loaded([]); true -> ok end.
|
case filelib:is_file(File) of false -> write_loaded([]); true -> ok end.
|
||||||
|
|
||||||
|
|
@ -155,23 +137,16 @@ stop_plugins(Names) ->
|
||||||
%% @doc List all available plugins
|
%% @doc List all available plugins
|
||||||
-spec(list() -> [emqx_types:plugin()]).
|
-spec(list() -> [emqx_types:plugin()]).
|
||||||
list() ->
|
list() ->
|
||||||
case emqx_config:get_env(plugins_etc_dir) of
|
StartedApps = names(started_app),
|
||||||
undefined ->
|
lists:map(fun({Name, _, _}) ->
|
||||||
[];
|
Plugin = plugin(Name),
|
||||||
PluginsEtc ->
|
case lists:member(Name, StartedApps) of
|
||||||
CfgFiles = filelib:wildcard("*.{conf,config}", PluginsEtc) ++ get_expand_plugin_config(),
|
true -> Plugin#plugin{active = true};
|
||||||
Plugins = [plugin(CfgFile) || CfgFile <- CfgFiles],
|
false -> Plugin
|
||||||
StartedApps = names(started_app),
|
end
|
||||||
lists:map(fun(Plugin = #plugin{name = Name}) ->
|
end, ekka_boot:all_module_attributes(emqx_plugin)).
|
||||||
case lists:member(Name, StartedApps) of
|
|
||||||
true -> Plugin#plugin{active = true};
|
|
||||||
false -> Plugin
|
|
||||||
end
|
|
||||||
end, Plugins)
|
|
||||||
end.
|
|
||||||
|
|
||||||
plugin(CfgFile) ->
|
plugin(AppName) ->
|
||||||
AppName = app_name(CfgFile),
|
|
||||||
case application:get_all_key(AppName) of
|
case application:get_all_key(AppName) of
|
||||||
{ok, Attrs} ->
|
{ok, Attrs} ->
|
||||||
Ver = proplists:get_value(vsn, Attrs, "0"),
|
Ver = proplists:get_value(vsn, Attrs, "0"),
|
||||||
|
|
@ -268,10 +243,6 @@ 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());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue