Skip to content

Commit

Permalink
Merge pull request #4071 from esl/drop_ejabberd_mod
Browse files Browse the repository at this point in the history
Put startup in mongooseim:start
  • Loading branch information
arcusfelis committed Aug 2, 2023
2 parents 6cef853 + dd2af70 commit 2dff20b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 59 deletions.
33 changes: 3 additions & 30 deletions src/ejabberd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@

-module(ejabberd).
-author('alexey@process-one.net').
-export([start/0,
stop/0,
get_pid_file/0,
-export([get_pid_file/0,
get_status_file/0,
get_so_path/0,
get_bin_path/0]).

-ignore_xref([get_bin_path/0, stop/0]).
get_so_path/0]).

-type lang() :: binary().

Expand All @@ -44,15 +39,7 @@
| {'xmlstreamerror', _}
| {'xmlstreamstart', Name :: any(), Attrs :: list()}.

-export_type([lang/0,
xml_stream_item/0
]).

start() ->
application:ensure_all_started(mongooseim).

stop() ->
application:stop(mongooseim).
-export_type([lang/0, xml_stream_item/0]).

-spec get_so_path() -> binary() | string().
get_so_path() ->
Expand All @@ -68,20 +55,6 @@ get_so_path() ->
Path
end.

-spec get_bin_path() -> binary() | string().
get_bin_path() ->
case os:getenv("EJABBERD_BIN_PATH") of
false ->
case code:priv_dir(ejabberd) of
{error, _} ->
".";
Path ->
filename:join([Path, "bin"])
end;
Path ->
Path
end.

-spec get_pid_file() -> 'false' | nonempty_string().
get_pid_file() ->
case os:getenv("EJABBERD_PID_PATH") of
Expand Down
2 changes: 0 additions & 2 deletions src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ start(normal, _Args) ->
mongoose_config:start(),
mongoose_metrics:init(),
db_init(),
application:start(cache_tab),

mongoose_graphql:init(),
translate:start(),
Expand Down Expand Up @@ -98,7 +97,6 @@ stop(_State) ->
?LOG_NOTICE(#{what => mongooseim_node_stopped, version => ?MONGOOSE_VERSION, node => node()}),
delete_pid_file(),
update_status_file(stopped),
%%ejabberd_debug:stop(),
ok.


Expand Down
10 changes: 6 additions & 4 deletions src/mongooseim.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
-export_type([host_type/0, host_type_or_global/0, domain_name/0]).

%% API
-export([start/0]).
-export([start/0, stop/0]).

-ignore_xref([start/0]).
-ignore_xref([start/0, stop/0]).

start() ->
application:start(mongooseim),
ejabberd:start().
application:ensure_all_started(mongooseim).

stop() ->
application:stop(mongooseim).
4 changes: 1 addition & 3 deletions test/cowboy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

-define(SERVER, "http://localhost:8080").

-import(ejabberd_helper, [start_ejabberd/1,
stop_ejabberd/0,
use_config_file/2,
-import(ejabberd_helper, [use_config_file/2,
start_ejabberd_with_config/2]).
-import(config_parser_helper, [default_config/1]).

Expand Down
16 changes: 2 additions & 14 deletions test/ejabberd_helper.erl
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
-module(ejabberd_helper).

-export([start_ejabberd/1,
stop_ejabberd/0,
use_config_file/2,
-export([use_config_file/2,
start_ejabberd_with_config/2,
copy/2,
data/2,
priv/2,
suite_priv/2]).


-spec start_ejabberd(any()) -> 'ok' | {error, any()}.
start_ejabberd(_Config) ->
{ok, _} = ejabberd:start().

-spec stop_ejabberd() -> 'ok' | {error, any()}.
stop_ejabberd() ->
application:stop(mongooseim).

-spec use_config_file(any(), file:name_all()) -> ok.
use_config_file(Config, ConfigFile) ->
%% To avoid "NIF library already loaded (reload disallowed since OTP 20)."
Expand All @@ -31,7 +20,7 @@ use_config_file(Config, ConfigFile) ->
-spec start_ejabberd_with_config(any(), file:name_all()) -> ok.
start_ejabberd_with_config(Config, ConfigFile) ->
use_config_file(Config, ConfigFile),
{ok, _} = start_ejabberd(Config).
{ok, _} = mongooseim:start().

copy(Src, Dst) ->
{ok, _} = file:copy(Src, Dst).
Expand Down Expand Up @@ -63,4 +52,3 @@ suite_priv(Config, PathSuffix) ->

preserve_trailing_slash($/, Path) -> Path ++ [$/];
preserve_trailing_slash(__, Path) -> Path.

8 changes: 3 additions & 5 deletions test/mongoose_config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

-include_lib("eunit/include/eunit.hrl").

-import(ejabberd_helper, [start_ejabberd/1,
start_ejabberd_with_config/2,
stop_ejabberd/0,
-import(ejabberd_helper, [start_ejabberd_with_config/2,
use_config_file/2,
copy/2,
data/2]).
Expand Down Expand Up @@ -152,7 +150,7 @@ cluster_load_from_file(Config) ->
[State, State] = mongoose_config:config_states(),
check_loaded_config(State),

ok = stop_ejabberd(),
ok = mongooseim:stop(),
stop_remote_ejabberd(SlaveNode),
check_removed_config().

Expand Down Expand Up @@ -238,7 +236,7 @@ start_remote_ejabberd_with_config(RemoteNode, C, ConfigFile) ->
rpc:call(RemoteNode, ejabberd_helper, start_ejabberd_with_config, [C, ConfigFile]).

stop_remote_ejabberd(SlaveNode) ->
rpc:call(SlaveNode, ejabberd_helper, stop_ejabberd, []).
rpc:call(SlaveNode, mongooseim, stop, []).

code_paths() ->
[filename:absname(Path) || Path <- code:get_path()].
Expand Down
2 changes: 1 addition & 1 deletion test/mongoose_listener_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ tcp_start_stop_reload(C) ->
{ok, Sock2} = gen_tcp:connect("localhost", ChgPort,[{active, false}, {packet, 2}]),
assert_connected(Sock2, ChgPort),

ok = ejabberd_helper:stop_ejabberd(),
ok = mongooseim:stop(),
ok.

assert_open(PortNo) ->
Expand Down

0 comments on commit 2dff20b

Please sign in to comment.