1 |
|
-module(mongoose_domain_sup). |
2 |
|
|
3 |
|
-behaviour(supervisor). |
4 |
|
|
5 |
|
-type pair() :: {mongooseim:domain_name(), mongooseim:host_type()}. |
6 |
|
|
7 |
|
-export([start_link/0, init/1]). |
8 |
|
-ignore_xref([start_link/0]). |
9 |
|
|
10 |
|
-export([start_link/2, restart_core/1]). |
11 |
|
-ignore_xref([start_link/2, restart_core/1]). |
12 |
|
|
13 |
|
start_link() -> |
14 |
4 |
supervisor:start_link({local, ?MODULE}, ?MODULE, []). |
15 |
|
|
16 |
|
start_link(Pairs, AllowedHostTypes) -> |
17 |
:-( |
supervisor:start_link({local, ?MODULE}, ?MODULE, [Pairs, AllowedHostTypes]). |
18 |
|
|
19 |
|
restart_core(Args) -> |
20 |
:-( |
supervisor:terminate_child(?MODULE, mongoose_domain_core), |
21 |
:-( |
supervisor:delete_child(?MODULE, mongoose_domain_core), |
22 |
:-( |
supervisor:start_child(?MODULE, worker_spec(mongoose_domain_core, fill_args(Args))). |
23 |
|
|
24 |
|
init(Args) -> |
25 |
4 |
DomainCore = worker_spec(mongoose_domain_core, fill_args(Args)), |
26 |
4 |
SubdomainCore = worker_spec(mongoose_subdomain_core, []), |
27 |
4 |
LazyRouting = worker_spec(mongoose_lazy_routing, []), |
28 |
4 |
{ok, {{one_for_one, 10, 1}, |
29 |
|
[DomainCore, SubdomainCore, LazyRouting]}}. |
30 |
|
|
31 |
|
worker_spec(Mod, Args) -> |
32 |
12 |
{Mod, {Mod, start_link, Args}, permanent, timer:seconds(5), worker, [Mod]}. |
33 |
|
|
34 |
|
%% Domains should be nameprepped using `jid:nameprep' |
35 |
|
-spec get_static_pairs() -> [pair()]. |
36 |
|
get_static_pairs() -> |
37 |
4 |
[{H, H} || H <- mongoose_config:get_opt(hosts)]. |
38 |
|
|
39 |
|
fill_args([]) -> |
40 |
4 |
Pairs = get_static_pairs(), |
41 |
4 |
AllowedHostTypes = mongoose_config:get_opt(host_types), |
42 |
4 |
[Pairs, AllowedHostTypes]; |
43 |
|
fill_args([_, _] = Args) -> |
44 |
:-( |
Args. |