mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Get rid of 'fs' package dependency
Certificates auto-reloading will be fixed later. For now to reload certificates call `reload-config` ejabberd command.
This commit is contained in:
parent
75450a62b3
commit
f39dbe6e49
@ -30,7 +30,6 @@
|
|||||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
||||||
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
|
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
|
||||||
{jose, ".*", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.8.4"}}},
|
{jose, ".*", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.8.4"}}},
|
||||||
{fs, ".*", {git, "https://github.com/synrc/fs", "bed9467"}},
|
|
||||||
{eimp, ".*", {git, "https://github.com/processone/eimp", {tag, "1.0.3"}}},
|
{eimp, ".*", {git, "https://github.com/processone/eimp", {tag, "1.0.3"}}},
|
||||||
{if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.21"}}}},
|
{if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.21"}}}},
|
||||||
{if_var_true, sip, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.22"}}}},
|
{if_var_true, sip, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.22"}}}},
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
-record(state, {validate = true :: boolean(),
|
-record(state, {validate = true :: boolean(),
|
||||||
notify = false :: boolean(),
|
|
||||||
paths = [] :: [file:filename()],
|
paths = [] :: [file:filename()],
|
||||||
certs = #{} :: map(),
|
certs = #{} :: map(),
|
||||||
graph :: digraph:graph(),
|
graph :: digraph:graph(),
|
||||||
@ -197,7 +196,6 @@ opt_type(_) ->
|
|||||||
%%% gen_server callbacks
|
%%% gen_server callbacks
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init([]) ->
|
init([]) ->
|
||||||
Notify = start_fs(),
|
|
||||||
process_flag(trap_exit, true),
|
process_flag(trap_exit, true),
|
||||||
ets:new(?MODULE, [named_table, public]),
|
ets:new(?MODULE, [named_table, public]),
|
||||||
ejabberd_hooks:add(route_registered, ?MODULE, route_registered, 50),
|
ejabberd_hooks:add(route_registered, ?MODULE, route_registered, 50),
|
||||||
@ -214,7 +212,7 @@ init([]) ->
|
|||||||
end,
|
end,
|
||||||
G = digraph:new([acyclic]),
|
G = digraph:new([acyclic]),
|
||||||
init_cache(),
|
init_cache(),
|
||||||
State = #state{validate = Validate, notify = Notify, graph = G},
|
State = #state{validate = Validate, graph = G},
|
||||||
case filelib:ensure_dir(filename:join(certs_dir(), "foo")) of
|
case filelib:ensure_dir(filename:join(certs_dir(), "foo")) of
|
||||||
ok ->
|
ok ->
|
||||||
clean_dir(certs_dir()),
|
clean_dir(certs_dir()),
|
||||||
@ -279,20 +277,6 @@ handle_call(_Request, _From, State) ->
|
|||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
handle_info({_, {fs, file_event}, {File, Events}}, State) ->
|
|
||||||
?DEBUG("got FS events for ~s: ~p", [File, Events]),
|
|
||||||
Path = iolist_to_binary(File),
|
|
||||||
case lists:member(modified, Events) of
|
|
||||||
true ->
|
|
||||||
case lists:member(Path, State#state.paths) of
|
|
||||||
true ->
|
|
||||||
handle_cast(config_reloaded, State);
|
|
||||||
false ->
|
|
||||||
{noreply, State}
|
|
||||||
end;
|
|
||||||
false ->
|
|
||||||
{noreply, State}
|
|
||||||
end;
|
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
?WARNING_MSG("unexpected info: ~p", [_Info]),
|
?WARNING_MSG("unexpected info: ~p", [_Info]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -419,7 +403,6 @@ build_chain_and_check(State) ->
|
|||||||
?DEBUG("Validating certificates", []),
|
?DEBUG("Validating certificates", []),
|
||||||
Errors = validate(CertPaths, State#state.validate),
|
Errors = validate(CertPaths, State#state.validate),
|
||||||
?DEBUG("Subscribing to file events", []),
|
?DEBUG("Subscribing to file events", []),
|
||||||
subscribe(State),
|
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({Cert, Why}) ->
|
fun({Cert, Why}) ->
|
||||||
Path = maps:get(Cert, State#state.certs),
|
Path = maps:get(Cert, State#state.certs),
|
||||||
@ -854,40 +837,6 @@ short_name_hash(_) ->
|
|||||||
"".
|
"".
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
-spec subscribe(state()) -> ok.
|
|
||||||
subscribe(#state{notify = true} = State) ->
|
|
||||||
lists:foreach(
|
|
||||||
fun(Path) ->
|
|
||||||
Dir = filename:dirname(Path),
|
|
||||||
Name = list_to_atom(integer_to_list(erlang:phash2(Dir))),
|
|
||||||
case fs:start_link(Name, Dir) of
|
|
||||||
{ok, _} ->
|
|
||||||
?DEBUG("Subscribed to FS events from ~s", [Dir]),
|
|
||||||
fs:subscribe(Name);
|
|
||||||
{error, _} ->
|
|
||||||
ok
|
|
||||||
end
|
|
||||||
end, State#state.paths);
|
|
||||||
subscribe(_) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
-spec start_fs() -> boolean().
|
|
||||||
start_fs() ->
|
|
||||||
application:load(fs),
|
|
||||||
application:set_env(fs, backwards_compatible, false),
|
|
||||||
case application:ensure_all_started(fs) of
|
|
||||||
{ok, _} -> true;
|
|
||||||
{error, {already_loaded, _}} -> true;
|
|
||||||
{error, Reason} ->
|
|
||||||
?ERROR_MSG("Failed to load 'fs' Erlang application: ~p; "
|
|
||||||
"certificates change detection will be disabled. "
|
|
||||||
"You should now manually run `ejabberdctl "
|
|
||||||
"reload_config` whenever certificates are changed "
|
|
||||||
"on disc",
|
|
||||||
[Reason]),
|
|
||||||
false
|
|
||||||
end.
|
|
||||||
|
|
||||||
wildcard(Path) when is_binary(Path) ->
|
wildcard(Path) when is_binary(Path) ->
|
||||||
wildcard(binary_to_list(Path));
|
wildcard(binary_to_list(Path));
|
||||||
wildcard(Path) ->
|
wildcard(Path) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user