summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2016-03-29 15:25:24 +0200
committerBadlop <badlop@process-one.net>2016-03-29 15:26:34 +0200
commit78a44d80996ce2dbc8d6a773920f81c8cfc89e89 (patch)
tree56835b1912ab1287d36fed2c49d5eaa3086fa55a /src
parentFix commands api option (diff)
Move start and stop_modules/0 from ejabberd_app to gen_mod (#1039)
Diffstat (limited to 'src')
-rw-r--r--src/ejabberd_app.erl42
-rw-r--r--src/gen_mod.erl53
2 files changed, 46 insertions, 49 deletions
diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl
index e493eac0..b25bf231 100644
--- a/src/ejabberd_app.erl
+++ b/src/ejabberd_app.erl
@@ -30,7 +30,7 @@
-behaviour(application).
--export([start_modules/0, start/2, prep_stop/1, stop/1,
+-export([start/2, prep_stop/1, stop/1,
init/0, opt_type/1]).
-include("ejabberd.hrl").
@@ -71,7 +71,7 @@ start(normal, _Args) ->
maybe_add_nameservers(),
ejabberd_auth:start(),
ejabberd_oauth:start(),
- start_modules(),
+ gen_mod:start_modules(),
ejabberd_listener:start_listeners(),
?INFO_MSG("ejabberd ~s is started in the node ~p", [?VERSION, node()]),
Sup;
@@ -83,7 +83,7 @@ start(_, _) ->
%% before shutting down the processes of the application.
prep_stop(State) ->
ejabberd_listener:stop_listeners(),
- stop_modules(),
+ gen_mod:stop_modules(),
ejabberd_admin:stop(),
broadcast_c2s_shutdown(),
timer:sleep(5000),
@@ -137,42 +137,6 @@ db_init() ->
ejabberd:start_app(mnesia, permanent),
mnesia:wait_for_tables(mnesia:system_info(local_tables), infinity).
-%% Start all the modules in all the hosts
-start_modules() ->
- lists:foreach(
- fun(Host) ->
- Modules = ejabberd_config:get_option(
- {modules, Host},
- fun(Mods) ->
- lists:map(
- fun({M, A}) when is_atom(M), is_list(A) ->
- {M, A}
- end, Mods)
- end, []),
- lists:foreach(
- fun({Module, Args}) ->
- gen_mod:start_module(Host, Module, Args)
- end, Modules)
- end, ?MYHOSTS).
-
-%% Stop all the modules in all the hosts
-stop_modules() ->
- lists:foreach(
- fun(Host) ->
- Modules = ejabberd_config:get_option(
- {modules, Host},
- fun(Mods) ->
- lists:map(
- fun({M, A}) when is_atom(M), is_list(A) ->
- {M, A}
- end, Mods)
- end, []),
- lists:foreach(
- fun({Module, _Args}) ->
- gen_mod:stop_module_keep_config(Host, Module)
- end, Modules)
- end, ?MYHOSTS).
-
connect_nodes() ->
Nodes = ejabberd_config:get_option(
cluster_nodes,
diff --git a/src/gen_mod.erl b/src/gen_mod.erl
index c45642d4..1044d095 100644
--- a/src/gen_mod.erl
+++ b/src/gen_mod.erl
@@ -35,7 +35,8 @@
get_module_opt/4, get_module_opt/5, get_module_opt_host/3,
loaded_modules/1, loaded_modules_with_opts/1,
get_hosts/2, get_module_proc/2, is_loaded/2,
- start_modules/1, default_db/1, v_db/1, opt_type/1]).
+ start_modules/0, start_modules/1, stop_modules/0, stop_modules/1,
+ default_db/1, v_db/1, opt_type/1]).
%%-export([behaviour_info/1]).
@@ -64,23 +65,38 @@ start() ->
{keypos, #ejabberd_module.module_host}]),
ok.
+-spec start_modules() -> any().
+
+%% Start all the modules in all the hosts
+start_modules() ->
+ lists:foreach(
+ fun(Host) ->
+ start_modules(Host)
+ end, ?MYHOSTS).
+
+get_modules_options(Host) ->
+ ejabberd_config:get_option(
+ {modules, Host},
+ fun(Mods) ->
+ lists:map(
+ fun({M, A}) when is_atom(M), is_list(A) ->
+ {M, A}
+ end, Mods)
+ end, []).
+
-spec start_modules(binary()) -> any().
start_modules(Host) ->
- Modules = ejabberd_config:get_option(
- {modules, Host},
- fun(L) when is_list(L) -> L end, []),
+ Modules = get_modules_options(Host),
lists:foreach(
- fun({Module, Opts}) ->
- start_module(Host, Module, Opts)
- end, Modules).
+ fun({Module, Opts}) ->
+ start_module(Host, Module, Opts)
+ end, Modules).
-spec start_module(binary(), atom()) -> any().
start_module(Host, Module) ->
- Modules = ejabberd_config:get_option(
- {modules, Host},
- fun(L) when is_list(L) -> L end, []),
+ Modules = get_modules_options(Host),
case lists:keyfind(Module, 1, Modules) of
{_, Opts} ->
start_module(Host, Module, Opts);
@@ -121,6 +137,23 @@ is_app_running(AppName) ->
lists:keymember(AppName, 1,
application:which_applications(Timeout)).
+-spec stop_modules() -> any().
+
+stop_modules() ->
+ lists:foreach(
+ fun(Host) ->
+ stop_modules(Host)
+ end, ?MYHOSTS).
+
+-spec stop_modules(binary()) -> any().
+
+stop_modules(Host) ->
+ Modules = get_modules_options(Host),
+ lists:foreach(
+ fun({Module, _Args}) ->
+ gen_mod:stop_module_keep_config(Host, Module)
+ end, Modules).
+
-spec stop_module(binary(), atom()) -> error | {aborted, any()} | {atomic, any()}.
stop_module(Host, Module) ->