25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

Fix loading of third-party modules at startup

Fixes #3019
This commit is contained in:
Evgeny Khramtsov 2019-11-07 10:47:11 +03:00
parent c48e972573
commit 94b74c0cbe
2 changed files with 18 additions and 10 deletions

View File

@ -283,6 +283,14 @@ beams(local) ->
Mods;
beams(external) ->
ExtMods = [Name || {Name, _Details} <- ext_mod:installed()],
lists:foreach(
fun(ExtMod) ->
ExtModPath = ext_mod:module_ebin_dir(ExtMod),
case lists:member(ExtModPath, code:get_path()) of
true -> ok;
false -> code:add_patha(ExtModPath)
end
end, ExtMods),
case application:get_env(ejabberd, external_beams) of
{ok, Path} ->
case lists:member(Path, code:get_path()) of
@ -468,14 +476,6 @@ validators(Mod, Disallowed) ->
end
end, proplists:get_keys(Mod:options()))).
-spec get_modules_configs() -> [binary()].
get_modules_configs() ->
Fs = [{filename:rootname(filename:basename(F)), F}
|| F <- filelib:wildcard(ext_mod:config_dir() ++ "/*.{yml,yaml}")
++ filelib:wildcard(ext_mod:modules_dir() ++ "/*/conf/*.{yml,yaml}")],
[unicode:characters_to_binary(proplists:get_value(F, Fs))
|| F <- proplists:get_keys(Fs)].
read_file(File) ->
read_file(File, [replace_macros, include_files, include_modules_configs]).
@ -484,7 +484,7 @@ read_file(File, Opts) ->
Ret = case filename:extension(File) of
Ex when Ex == <<".yml">> orelse Ex == <<".yaml">> ->
Files = case proplists:get_bool(include_modules_configs, Opts2) of
true -> get_modules_configs();
true -> ext_mod:modules_configs();
false -> []
end,
lists:foreach(

View File

@ -34,7 +34,7 @@
install/1, uninstall/1, upgrade/0, upgrade/1, add_paths/0,
add_sources/1, add_sources/2, del_sources/1, modules_dir/0,
config_dir/0, get_commands_spec/0]).
-export([modules_configs/0, module_ebin_dir/1]).
-export([compile_erlang_file/2, compile_elixir_file/2]).
%% gen_server callbacks
@ -426,6 +426,14 @@ config_dir() ->
DefaultDir = filename:join(modules_dir(), "conf"),
getenv("CONTRIB_MODULES_CONF_DIR", DefaultDir).
-spec modules_configs() -> [binary()].
modules_configs() ->
Fs = [{filename:rootname(filename:basename(F)), F}
|| F <- filelib:wildcard(config_dir() ++ "/*.{yml,yaml}")
++ filelib:wildcard(modules_dir() ++ "/*/conf/*.{yml,yaml}")],
[unicode:characters_to_binary(proplists:get_value(F, Fs))
|| F <- proplists:get_keys(Fs)].
module_lib_dir(Package) ->
filename:join(modules_dir(), Package).