-module(ejabberd).
-author('alexey@process-one.net').
+-compile({no_auto_import, [{halt, 0}]}).
-protocol({xep, 4, '2.9'}).
-protocol({xep, 86, '1.0'}).
-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").
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
?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.
{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}.
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.
[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 "
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.
#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.
"Failed to convert '~s' table to binary: ~p",
[Tab, Err])),
?CRITICAL_MSG(ErrTxt, []),
- timer:sleep(1000),
- halt(string:substr(ErrTxt, 1, 199)).
+ ejabberd:halt().