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

If extauth script crashes, ejabberd should restart it (EJAB-1428)

This commit is contained in:
Badlop 2011-04-11 21:27:19 +02:00
parent 7d7621c67c
commit 05e3893f60

View File

@ -45,11 +45,18 @@
start(Host, ExtPrg) -> start(Host, ExtPrg) ->
lists:foreach( lists:foreach(
fun(This) -> fun(This) ->
spawn(?MODULE, init, [get_process_name(Host, This), ExtPrg]) start_instance(get_process_name(Host, This), ExtPrg)
end, end,
lists:seq(0, get_instances(Host)-1) lists:seq(0, get_instances(Host)-1)
). ).
start_instance(ProcessName, ExtPrg) ->
spawn(?MODULE, init, [ProcessName, ExtPrg]).
restart_instance(ProcessName, ExtPrg) ->
unregister(ProcessName),
start_instance(ProcessName, ExtPrg).
init(ProcessName, ExtPrg) -> init(ProcessName, ExtPrg) ->
register(ProcessName, self()), register(ProcessName, self()),
process_flag(trap_exit,true), process_flag(trap_exit,true),
@ -125,8 +132,7 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
Timeout -> Timeout ->
?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]), ?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]),
Caller ! {eauth, false}, Caller ! {eauth, false},
unregister(ProcessName), Pid = restart_instance(ProcessName, ExtPrg),
Pid = spawn(?MODULE, init, [ProcessName, ExtPrg]),
flush_buffer_and_forward_messages(Pid), flush_buffer_and_forward_messages(Pid),
exit(port_terminated) exit(port_terminated)
end; end;
@ -137,7 +143,9 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
exit(normal) exit(normal)
end; end;
{'EXIT', Port, Reason} -> {'EXIT', Port, Reason} ->
?CRITICAL_MSG("~p ~n", [Reason]), ?CRITICAL_MSG("extauth script has exitted abruptly with reason '~p'", [Reason]),
Pid = restart_instance(ProcessName, ExtPrg),
flush_buffer_and_forward_messages(Pid),
exit(port_terminated) exit(port_terminated)
end. end.