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

View File

@ -62,8 +62,7 @@ start(normal, _Args) ->
{ok, SupPid};
Err ->
?CRITICAL_MSG("Failed to start ejabberd application: ~p", [Err]),
timer:sleep(1000),
halt("Refer to ejabberd log files to diagnose the problem")
ejabberd:halt()
end;
start(_, _) ->
{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) ->
case [Vsn || {ejabberd, _Desc, Vsn} <- application:which_applications()] of
[] ->
timer:sleep(1000),
halt(string:substr(ExitText, 1, 199));
ejabberd:halt();
[_] ->
exit(ExitText)
end.

View File

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

View File

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