25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Simplify ejabberd_sup code

This commit is contained in:
Evgeniy Khramtsov 2018-03-03 18:05:12 +03:00
parent dbf1cabdcd
commit 0d3637d18f

View File

@ -30,150 +30,58 @@
-export([start_link/0, init/1]). -export([start_link/0, init/1]).
-define(SHUTDOWN_TIMEOUT, timer:seconds(30)).
start_link() -> start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []). supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) -> init([]) ->
Hooks =
{ejabberd_hooks,
{ejabberd_hooks, start_link, []},
permanent,
brutal_kill,
worker,
[ejabberd_hooks]},
Cluster = {ejabberd_cluster,
{ejabberd_cluster, start_link, []},
permanent,
5000,
worker,
[ejabberd_cluster]},
S2S =
{ejabberd_s2s,
{ejabberd_s2s, start_link, []},
permanent,
brutal_kill,
worker,
[ejabberd_s2s]},
Captcha =
{ejabberd_captcha,
{ejabberd_captcha, start_link, []},
permanent,
brutal_kill,
worker,
[ejabberd_captcha]},
Listener =
{ejabberd_listener,
{ejabberd_listener, start_link, []},
permanent,
infinity,
supervisor,
[ejabberd_listener]},
S2SInSupervisor =
{ejabberd_s2s_in_sup,
{ejabberd_tmp_sup, start_link,
[ejabberd_s2s_in_sup, ejabberd_s2s_in]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
S2SOutSupervisor =
{ejabberd_s2s_out_sup,
{ejabberd_tmp_sup, start_link,
[ejabberd_s2s_out_sup, ejabberd_s2s_out]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
ServiceSupervisor =
{ejabberd_service_sup,
{ejabberd_tmp_sup, start_link,
[ejabberd_service_sup, ejabberd_service]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
BackendSupervisor = {ejabberd_backend_sup,
{ejabberd_backend_sup, start_link, []},
permanent, infinity, supervisor,
[ejabberd_backend_sup]},
ACL = {acl, {acl, start_link, []},
permanent, 5000, worker, [acl]},
Shaper = {shaper, {shaper, start_link, []},
permanent, 5000, worker, [shaper]},
SQLSupervisor = {ejabberd_rdbms,
{ejabberd_rdbms, start_link, []},
permanent, infinity, supervisor, [ejabberd_rdbms]},
RiakSupervisor = {ejabberd_riak_sup,
{ejabberd_riak_sup, start_link, []},
permanent, infinity, supervisor, [ejabberd_riak_sup]},
RedisSupervisor = {ejabberd_redis_sup,
{ejabberd_redis_sup, start_link, []},
permanent, infinity, supervisor, [ejabberd_redis_sup]},
Router = {ejabberd_router, {ejabberd_router, start_link, []},
permanent, 5000, worker, [ejabberd_router]},
RouterMulticast = {ejabberd_router_multicast,
{ejabberd_router_multicast, start_link, []},
permanent, 5000, worker, [ejabberd_router_multicast]},
Local = {ejabberd_local, {ejabberd_local, start_link, []},
permanent, 5000, worker, [ejabberd_local]},
SM = {ejabberd_sm, {ejabberd_sm, start_link, []},
permanent, 5000, worker, [ejabberd_sm]},
GenModSupervisor = {ejabberd_gen_mod_sup, {gen_mod, start_link, []},
permanent, infinity, supervisor, [gen_mod]},
ExtMod = {ext_mod, {ext_mod, start_link, []},
permanent, 5000, worker, [ext_mod]},
Auth = {ejabberd_auth, {ejabberd_auth, start_link, []},
permanent, 5000, worker, [ejabberd_auth]},
OAuth = {ejabberd_oauth, {ejabberd_oauth, start_link, []},
permanent, 5000, worker, [ejabberd_oauth]},
Translation = {translate, {translate, start_link, []},
permanent, 5000, worker, [translate]},
AccessPerms = {ejabberd_access_permissions,
{ejabberd_access_permissions, start_link, []},
permanent, 5000, worker, [ejabberd_access_permissions]},
Ctl = {ejabberd_ctl, {ejabberd_ctl, start_link, []},
permanent, 5000, worker, [ejabberd_ctl]},
Commands = {ejabberd_commands, {ejabberd_commands, start_link, []},
permanent, 5000, worker, [ejabberd_commands]},
Admin = {ejabberd_admin, {ejabberd_admin, start_link, []},
permanent, 5000, worker, [ejabberd_admin]},
CyrSASL = {cyrsasl, {cyrsasl, start_link, []},
permanent, 5000, worker, [cyrsasl]},
PKIX = {ejabberd_pkix, {ejabberd_pkix, start_link, []},
permanent, 5000, worker, [ejabberd_pkix]},
ACME = {ejabberd_acme, {ejabberd_acme, start_link, []},
permanent, 5000, worker, [ejabberd_acme]},
IQ = {ejabberd_iq, {ejabberd_iq, start_link, []},
permanent, 5000, worker, [ejabberd_iq]},
{ok, {{one_for_one, 10, 1}, {ok, {{one_for_one, 10, 1},
[Hooks, [worker(ejabberd_hooks),
Cluster, worker(ejabberd_cluster),
CyrSASL, worker(cyrsasl),
Translation, worker(translate),
AccessPerms, worker(ejabberd_access_permissions),
Ctl, worker(ejabberd_ctl),
Commands, worker(ejabberd_commands),
Admin, worker(ejabberd_admin),
PKIX, worker(ejabberd_pkix),
ACME, worker(ejabberd_acme),
Listener, supervisor(ejabberd_listener),
S2S, worker(ejabberd_s2s),
S2SInSupervisor, simple_supervisor(ejabberd_s2s_in),
S2SOutSupervisor, simple_supervisor(ejabberd_s2s_out),
ServiceSupervisor, simple_supervisor(ejabberd_service),
ACL, worker(acl),
Shaper, worker(shaper),
BackendSupervisor, supervisor(ejabberd_backend_sup),
SQLSupervisor, supervisor(ejabberd_rdbms),
RiakSupervisor, supervisor(ejabberd_riak_sup),
RedisSupervisor, supervisor(ejabberd_redis_sup),
IQ, worker(ejabberd_iq),
Router, worker(ejabberd_router),
RouterMulticast, worker(ejabberd_router_multicast),
Local, worker(ejabberd_local),
SM, worker(ejabberd_sm),
Captcha, worker(ejabberd_captcha),
ExtMod, worker(ext_mod),
GenModSupervisor, supervisor(ejabberd_gen_mod_sup, gen_mod),
Auth, worker(ejabberd_auth),
OAuth]}}. worker(ejabberd_oauth)]}}.
%%%===================================================================
%%% Internal functions
%%%===================================================================
worker(Mod) ->
{Mod, {Mod, start_link, []}, permanent, ?SHUTDOWN_TIMEOUT, worker, [Mod]}.
supervisor(Mod) ->
supervisor(Mod, Mod).
supervisor(Name, Mod) ->
{Name, {Mod, start_link, []}, permanent, infinity, supervisor, [Mod]}.
simple_supervisor(Mod) ->
Name = list_to_atom(atom_to_list(Mod) ++ "_sup"),
{Name, {ejabberd_tmp_sup, start_link, [Name, Mod]},
permanent, infinity, supervisor, [ejabberd_tmp_sup]}.