26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-30 17:43:57 +01:00

Start even if there are problems with fs application

This commit is contained in:
Evgeniy Khramtsov 2017-11-01 08:34:14 +03:00
parent 170be1fbd5
commit 35dc164233

View File

@ -38,6 +38,7 @@
-include("jid.hrl"). -include("jid.hrl").
-record(state, {validate = true :: boolean(), -record(state, {validate = true :: boolean(),
notify = false :: boolean(),
paths = [] :: [file:filename()], paths = [] :: [file:filename()],
certs = #{} :: map(), certs = #{} :: map(),
keys = [] :: [public_key:private_key()]}). keys = [] :: [public_key:private_key()]}).
@ -158,9 +159,7 @@ opt_type(_) ->
%%% gen_server callbacks %%% gen_server callbacks
%%%=================================================================== %%%===================================================================
init([]) -> init([]) ->
application:load(fs), Notify = start_fs(),
application:set_env(fs, backwards_compatible, false),
ejabberd:start_app(fs),
process_flag(trap_exit, true), process_flag(trap_exit, true),
ets:new(?MODULE, [named_table, public, bag]), ets:new(?MODULE, [named_table, public, bag]),
ejabberd_hooks:add(route_registered, ?MODULE, route_registered, 50), ejabberd_hooks:add(route_registered, ?MODULE, route_registered, 50),
@ -175,7 +174,7 @@ init([]) ->
if Validate -> check_ca_dir(); if Validate -> check_ca_dir();
true -> ok true -> ok
end, end,
State = #state{validate = Validate}, State = #state{validate = Validate, notify = Notify},
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()),
@ -679,7 +678,7 @@ short_name_hash(_) ->
-endif. -endif.
-spec subscribe(state()) -> ok. -spec subscribe(state()) -> ok.
subscribe(State) -> subscribe(#state{notify = true} = State) ->
lists:foreach( lists:foreach(
fun(Path) -> fun(Path) ->
Dir = filename:dirname(Path), Dir = filename:dirname(Path),
@ -691,4 +690,20 @@ subscribe(State) ->
{error, _} -> {error, _} ->
ok ok
end end
end, State#state.paths). 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",
[Reason]),
false
end.