aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2018-03-29 12:14:31 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2018-03-29 12:14:31 +0300
commit9373ad20ca0ffa457062e3c5c4593bc67ee23c2b (patch)
treeba5fb93143328ba9efe73a089cb60349db738286 /src
parentRemove unused variable (diff)
Don't produce a crash dump during intentional exit
Also halt faster without relying on timeouts for buffers flushing
Diffstat (limited to 'src')
-rw-r--r--src/ejabberd.erl11
-rw-r--r--src/ejabberd_app.erl3
-rw-r--r--src/ejabberd_config.erl3
-rw-r--r--src/gen_mod.erl13
-rw-r--r--src/pubsub_migrate.erl3
5 files changed, 17 insertions, 16 deletions
diff --git a/src/ejabberd.erl b/src/ejabberd.erl
index 356fd66c7..4740bd034 100644
--- a/src/ejabberd.erl
+++ b/src/ejabberd.erl
@@ -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.
diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl
index a7e03d990..f1066815f 100644
--- a/src/ejabberd_app.erl
+++ b/src/ejabberd_app.erl
@@ -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}.
diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl
index cf3d099cc..3f88df59a 100644
--- a/src/ejabberd_config.erl
+++ b/src/ejabberd_config.erl
@@ -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.
diff --git a/src/gen_mod.erl b/src/gen_mod.erl
index bf83fe13d..1ebaa17c3 100644
--- a/src/gen_mod.erl
+++ b/src/gen_mod.erl
@@ -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.
diff --git a/src/pubsub_migrate.erl b/src/pubsub_migrate.erl
index 6b5900279..0728da765 100644
--- a/src/pubsub_migrate.erl
+++ b/src/pubsub_migrate.erl
@@ -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().