25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Fix http-bind supervisor to support multiple vhosts (EJAB-1321)

This commit is contained in:
Badlop 2010-11-17 20:29:36 +01:00
parent 690c56ca6d
commit c2dface515
2 changed files with 19 additions and 29 deletions

View File

@ -110,6 +110,8 @@
-define(PROCESS_DELAY_MIN, 0).
-define(PROCESS_DELAY_MAX, 1000).
%% Line copied from mod_http_bind.erl
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%%%----------------------------------------------------------------------
%%% API
@ -118,7 +120,8 @@
%% supervisor
start(XMPPDomain, Sid, Key, IP) ->
?DEBUG("Starting session", []),
case catch supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]) of
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME_MHB),
case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP]) of
{ok, Pid} ->
{ok, Pid};
{error, _} = Err ->
@ -129,6 +132,9 @@ start(XMPPDomain, Sid, Key, IP) ->
?ERROR_MSG("Cannot start HTTP bind session: ~p", [Err]),
Err
end;
{'EXIT', {noproc, _}} = Exit ->
?DEBUG("Cannot start HTTP bind session because mod_http_bind seems stopped:~n~p", [Exit]),
{error, Exit};
Exit ->
?ERROR_MSG("Cannot start HTTP bind session: ~p", [Exit]),
{error, Exit}

View File

@ -49,6 +49,8 @@
-include("ejabberd_http.hrl").
-include("http_bind.hrl").
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%% Duplicated from ejabberd_http_bind.
%% TODO: move to hrl file.
-record(http_bind, {id, pid, to, hold, wait, process_delay, version}).
@ -101,41 +103,23 @@ get_human_html_xmlel() ->
%%%----------------------------------------------------------------------
%%% BEHAVIOUR CALLBACKS
%%%----------------------------------------------------------------------
start(_Host, _Opts) ->
start(Host, _Opts) ->
setup_database(),
HTTPBindSupervisor =
{ejabberd_http_bind_sup,
Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
ChildSpec =
{Proc,
{ejabberd_tmp_sup, start_link,
[ejabberd_http_bind_sup, ejabberd_http_bind]},
[Proc, ejabberd_http_bind]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
case supervisor:start_child(ejabberd_sup, HTTPBindSupervisor) of
{ok, _Pid} ->
ok;
{ok, _Pid, _Info} ->
ok;
{error, {already_started, _PidOther}} ->
% mod_http_bind is already started so it will not be started again
ok;
{error, Error} ->
exit({start_child_error, Error})
end.
supervisor:start_child(ejabberd_sup, ChildSpec).
stop(_Host) ->
case supervisor:terminate_child(ejabberd_sup, ejabberd_http_bind_sup) of
ok ->
ok;
{error, Error} ->
exit({terminate_child_error, Error})
end,
case supervisor:delete_child(ejabberd_sup, ejabberd_http_bind_sup) of
ok ->
ok;
{error, Error2} ->
exit({delete_child_error, Error2})
end.
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc).
setup_database() ->
migrate_database(),