aboutsummaryrefslogtreecommitdiff
path: root/src/mod_http_fileserver.erl
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-02-22 19:46:47 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-02-22 19:46:47 +0300
commit3c4057ff553928d4e4ab40e410dbc6a478dd8206 (patch)
treea0272f84a1221db928cfd4c9f44d9bed6e196bc8 /src/mod_http_fileserver.erl
parentMake sure all hooks are called with proper host (diff)
Reload modules when reloading configuration file
Diffstat (limited to 'src/mod_http_fileserver.erl')
-rw-r--r--src/mod_http_fileserver.erl43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/mod_http_fileserver.erl b/src/mod_http_fileserver.erl
index 143ab03f5..79eeed5ac 100644
--- a/src/mod_http_fileserver.erl
+++ b/src/mod_http_fileserver.erl
@@ -31,7 +31,7 @@
-behaviour(gen_server).
%% gen_mod callbacks
--export([start/2, stop/1]).
+-export([start/2, stop/1, reload/3]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -90,6 +90,10 @@ start(Host, Opts) ->
stop(Host) ->
gen_mod:stop_child(?MODULE, Host).
+reload(Host, NewOpts, OldOpts) ->
+ Proc = get_proc_name(Host),
+ gen_server:cast(Proc, {reload, Host, NewOpts, OldOpts}).
+
depends(_Host, _Opts) ->
[].
@@ -105,19 +109,9 @@ depends(_Host, _Opts) ->
%%--------------------------------------------------------------------
init([Host, Opts]) ->
try initialize(Host, Opts) of
- {DocRoot, AccessLog, AccessLogFD, DirectoryIndices,
- CustomHeaders, DefaultContentType, ContentTypes,
- UserAccess} ->
+ State ->
process_flag(trap_exit, true),
- {ok, #state{host = Host,
- accesslog = AccessLog,
- accesslogfd = AccessLogFD,
- docroot = DocRoot,
- directory_indices = DirectoryIndices,
- custom_headers = CustomHeaders,
- default_content_type = DefaultContentType,
- content_types = ContentTypes,
- user_access = UserAccess}}
+ {ok, State}
catch
throw:Reason ->
{stop, Reason}
@@ -163,9 +157,15 @@ initialize(Host, Opts) ->
?INFO_MSG("known content types: ~s",
[str:join([[$*, K, " -> ", V] || {K, V} <- ContentTypes],
<<", ">>)]),
- {DocRoot, AccessLog, AccessLogFD, DirectoryIndices,
- CustomHeaders, DefaultContentType, ContentTypes, UserAccess}.
-
+ #state{host = Host,
+ accesslog = AccessLog,
+ accesslogfd = AccessLogFD,
+ docroot = DocRoot,
+ directory_indices = DirectoryIndices,
+ custom_headers = CustomHeaders,
+ default_content_type = DefaultContentType,
+ content_types = ContentTypes,
+ user_access = UserAccess}.
%% @spec (AdminCTs::[CT], Default::[CT]) -> [CT]
%% where CT = {Extension::string(), Value}
@@ -251,7 +251,16 @@ handle_cast({add_to_log, FileSize, Code, Request}, State) ->
handle_cast(reopen_log, State) ->
FD2 = reopen_log(State#state.accesslog, State#state.accesslogfd),
{noreply, State#state{accesslogfd = FD2}};
-handle_cast(_Msg, State) ->
+handle_cast({reload, Host, NewOpts, _OldOpts}, OldState) ->
+ try initialize(Host, NewOpts) of
+ NewState ->
+ FD = reopen_log(NewState#state.accesslog, OldState#state.accesslogfd),
+ {noreply, NewState#state{accesslogfd = FD}}
+ catch throw:_ ->
+ {noreply, OldState}
+ end;
+handle_cast(Msg, State) ->
+ ?WARNING_MSG("unexpected cast: ~p", [Msg]),
{noreply, State}.
%%--------------------------------------------------------------------