24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-16 22:05:29 +02:00

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

This commit is contained in:
Badlop 2010-11-17 20:14:59 +01:00
parent cfd377b98e
commit 808029b868
2 changed files with 16 additions and 29 deletions

View File

@ -112,6 +112,8 @@
-define(PROCESS_DELAY_MIN, 0). -define(PROCESS_DELAY_MIN, 0).
-define(PROCESS_DELAY_MAX, 1000). -define(PROCESS_DELAY_MAX, 1000).
%% Line copied from mod_http_bind.erl
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
@ -120,7 +122,8 @@
%% supervisor %% supervisor
start(XMPPDomain, Sid, Key, IP) -> start(XMPPDomain, Sid, Key, IP) ->
?DEBUG("Starting session", []), ?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}; {ok, Pid} -> {ok, Pid};
_ -> check_bind_module(XMPPDomain), _ -> check_bind_module(XMPPDomain),
{error, "Cannot start HTTP bind session"} {error, "Cannot start HTTP bind session"}

View File

@ -48,6 +48,8 @@
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("http_bind.hrl"). -include("http_bind.hrl").
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%% Duplicated from ejabberd_http_bind. %% Duplicated from ejabberd_http_bind.
%% TODO: move to hrl file. %% TODO: move to hrl file.
-record(http_bind, {id, pid, to, hold, wait, process_delay, version}). -record(http_bind, {id, pid, to, hold, wait, process_delay, version}).
@ -98,41 +100,23 @@ get_human_html_xmlel() ->
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% BEHAVIOUR CALLBACKS %%% BEHAVIOUR CALLBACKS
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(_Host, _Opts) -> start(Host, _Opts) ->
setup_database(), setup_database(),
HTTPBindSupervisor = Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
{ejabberd_http_bind_sup, ChildSpec =
{Proc,
{ejabberd_tmp_sup, start_link, {ejabberd_tmp_sup, start_link,
[ejabberd_http_bind_sup, ejabberd_http_bind]}, [Proc, ejabberd_http_bind]},
permanent, permanent,
infinity, infinity,
supervisor, supervisor,
[ejabberd_tmp_sup]}, [ejabberd_tmp_sup]},
case supervisor:start_child(ejabberd_sup, HTTPBindSupervisor) of supervisor:start_child(ejabberd_sup, ChildSpec).
{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.
stop(_Host) -> stop(Host) ->
case supervisor:terminate_child(ejabberd_sup, ejabberd_http_bind_sup) of Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
ok -> supervisor:terminate_child(ejabberd_sup, Proc),
ok; supervisor:delete_child(ejabberd_sup, Proc).
{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.
setup_database() -> setup_database() ->
migrate_database(), migrate_database(),