24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

Don't produce a crash dump during intentional exit

Also halt faster without relying on timeouts for buffers flushing
This commit is contained in:
Evgeniy Khramtsov 2018-03-29 12:14:31 +03:00
parent b283cfa6f2
commit 9373ad20ca
5 changed files with 17 additions and 16 deletions

View File

@ -25,6 +25,7 @@
-module(ejabberd). -module(ejabberd).
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-compile({no_auto_import, [{halt, 0}]}).
-protocol({xep, 4, '2.9'}). -protocol({xep, 4, '2.9'}).
-protocol({xep, 86, '1.0'}). -protocol({xep, 86, '1.0'}).
@ -36,7 +37,7 @@
-protocol({xep, 243, '1.0'}). -protocol({xep, 243, '1.0'}).
-protocol({xep, 270, '1.0'}). -protocol({xep, 270, '1.0'}).
-export([start/0, stop/0, start_app/1, start_app/2, -export([start/0, stop/0, halt/0, start_app/1, start_app/2,
get_pid_file/0, check_app/1, module_name/1]). get_pid_file/0, check_app/1, module_name/1]).
-include("logger.hrl"). -include("logger.hrl").
@ -49,6 +50,11 @@ stop() ->
application:stop(ejabberd). application:stop(ejabberd).
%%ejabberd_cover:stop(). %%ejabberd_cover:stop().
halt() ->
application:stop(lager),
application:stop(sasl),
erlang:halt(1, [{flush, true}]).
%% @spec () -> false | string() %% @spec () -> false | string()
get_pid_file() -> get_pid_file() ->
case os:getenv("EJABBERD_PID_PATH") of case os:getenv("EJABBERD_PID_PATH") of
@ -131,8 +137,7 @@ exit_or_halt(Reason, StartFlag) ->
?CRITICAL_MSG(Reason, []), ?CRITICAL_MSG(Reason, []),
if StartFlag -> if StartFlag ->
%% Wait for the critical message is written in the console/log %% Wait for the critical message is written in the console/log
timer:sleep(1000), halt();
halt(string:substr(lists:flatten(Reason), 1, 199));
true -> true ->
erlang:error(application_start_failed) erlang:error(application_start_failed)
end. end.

View File

@ -62,8 +62,7 @@ start(normal, _Args) ->
{ok, SupPid}; {ok, SupPid};
Err -> Err ->
?CRITICAL_MSG("Failed to start ejabberd application: ~p", [Err]), ?CRITICAL_MSG("Failed to start ejabberd application: ~p", [Err]),
timer:sleep(1000), ejabberd:halt()
halt("Refer to ejabberd log files to diagnose the problem")
end; end;
start(_, _) -> start(_, _) ->
{error, badarg}. {error, badarg}.

View File

@ -455,8 +455,7 @@ get_config_lines2(Fd, Data, CurrLine, [NextWanted | LNumbers], R) when is_list(D
exit_or_halt(ExitText) -> exit_or_halt(ExitText) ->
case [Vsn || {ejabberd, _Desc, Vsn} <- application:which_applications()] of case [Vsn || {ejabberd, _Desc, Vsn} <- application:which_applications()] of
[] -> [] ->
timer:sleep(1000), ejabberd:halt();
halt(string:substr(ExitText, 1, 199));
[_] -> [_] ->
exit(ExitText) exit(ExitText)
end. end.

View File

@ -152,7 +152,7 @@ sort_modules(Host, ModOpts) ->
[Mod, DepMod]), [Mod, DepMod]),
?ERROR_MSG(ErrTxt, []), ?ERROR_MSG(ErrTxt, []),
digraph:del_vertex(G, Mod), digraph:del_vertex(G, Mod),
maybe_halt_ejabberd(ErrTxt); maybe_halt_ejabberd();
false when Type == soft -> false when Type == soft ->
?WARNING_MSG("Module '~s' is recommended for " ?WARNING_MSG("Module '~s' is recommended for "
"module '~s' but is not found in " "module '~s' but is not found in "
@ -240,11 +240,11 @@ start_module(Host, Module, Opts0, Order, NeedValidation) ->
erlang:get_stacktrace()]) erlang:get_stacktrace()])
end, end,
?CRITICAL_MSG(ErrorText, []), ?CRITICAL_MSG(ErrorText, []),
maybe_halt_ejabberd(ErrorText), maybe_halt_ejabberd(),
erlang:raise(Class, Reason, erlang:get_stacktrace()) erlang:raise(Class, Reason, erlang:get_stacktrace())
end; end;
{error, ErrorText} -> {error, _ErrorText} ->
maybe_halt_ejabberd(ErrorText) maybe_halt_ejabberd()
end. end.
-spec reload_modules(binary()) -> ok. -spec reload_modules(binary()) -> ok.
@ -318,14 +318,13 @@ store_options(Host, Module, Opts, Order) ->
#ejabberd_module{module_host = {Module, Host}, #ejabberd_module{module_host = {Module, Host},
opts = Opts, order = Order}). opts = Opts, order = Order}).
maybe_halt_ejabberd(ErrorText) -> maybe_halt_ejabberd() ->
case is_app_running(ejabberd) of case is_app_running(ejabberd) of
false -> false ->
?CRITICAL_MSG("ejabberd initialization was aborted " ?CRITICAL_MSG("ejabberd initialization was aborted "
"because a module start failed.", "because a module start failed.",
[]), []),
timer:sleep(3000), ejabberd:halt();
erlang:halt(string:substr(lists:flatten(ErrorText), 1, 199));
true -> true ->
ok ok
end. end.

View File

@ -529,5 +529,4 @@ report_and_stop(Tab, Err) ->
"Failed to convert '~s' table to binary: ~p", "Failed to convert '~s' table to binary: ~p",
[Tab, Err])), [Tab, Err])),
?CRITICAL_MSG(ErrTxt, []), ?CRITICAL_MSG(ErrTxt, []),
timer:sleep(1000), ejabberd:halt().
halt(string:substr(ErrTxt, 1, 199)).