%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([start_link/0, opt_type/1]).
+-export([start_link/0, opt_type/1, register_certfiles/0]).
-include("ejabberd.hrl").
-include("logger.hrl").
init([]) ->
case filelib:ensure_dir(filename:join(acme_certs_dir(), "foo")) of
ok ->
+ ejabberd_hooks:add(config_reloaded, ?MODULE, register_certfiles, 40),
ejabberd_commands:register_commands(get_commands_spec()),
register_certfiles(),
{ok, #state{}};
{noreply, State}.
terminate(_Reason, _State) ->
+ ejabberd_hooks:delete(config_reloaded, ?MODULE, register_certfiles, 40),
ejabberd_commands:unregister_commands(get_commands_spec()).
code_change(_OldVsn, State, _Extra) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
config_reloaded() ->
- gen_server:cast(?MODULE, config_reloaded).
+ gen_server:call(?MODULE, config_reloaded, 60000).
opt_type(ca_path) ->
fun(Path) -> iolist_to_binary(Path) end;
{error, _} ->
{reply, ok, State}
end;
-handle_call(_Request, _From, State) ->
- Reply = ok,
- {reply, Reply, State}.
-
-handle_cast(config_reloaded, State) ->
+handle_call(config_reloaded, _From, State) ->
State1 = State#state{paths = [], certs = #{}, keys = []},
case add_certfiles(State1) of
{ok, State2} ->
- {noreply, State2};
- {error, _} ->
- {noreply, State}
+ {reply, ok, State2};
+ {error, _} = Err ->
+ {reply, Err, State}
end;
+handle_call(_Request, _From, State) ->
+ Reply = ok,
+ {reply, Reply, State}.
+
handle_cast(_Msg, State) ->
{noreply, State}.