1 |
|
%%%---------------------------------------------------------------------- |
2 |
|
%%% File : ejabberd_sup.erl |
3 |
|
%%% Author : Alexey Shchepin <alexey@process-one.net> |
4 |
|
%%% Purpose : Erlang/OTP supervisor |
5 |
|
%%% Created : 31 Jan 2003 by Alexey Shchepin <alexey@process-one.net> |
6 |
|
%%% |
7 |
|
%%% |
8 |
|
%%% ejabberd, Copyright (C) 2002-2011 ProcessOne |
9 |
|
%%% |
10 |
|
%%% This program is free software; you can redistribute it and/or |
11 |
|
%%% modify it under the terms of the GNU General Public License as |
12 |
|
%%% published by the Free Software Foundation; either version 2 of the |
13 |
|
%%% License, or (at your option) any later version. |
14 |
|
%%% |
15 |
|
%%% This program is distributed in the hope that it will be useful, |
16 |
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 |
|
%%% General Public License for more details. |
19 |
|
%%% |
20 |
|
%%% You should have received a copy of the GNU General Public License |
21 |
|
%%% along with this program; if not, write to the Free Software |
22 |
|
%%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 |
|
%%% |
24 |
|
%%%---------------------------------------------------------------------- |
25 |
|
|
26 |
|
-module(ejabberd_sup). |
27 |
|
-author('alexey@process-one.net'). |
28 |
|
|
29 |
|
-behaviour(supervisor). |
30 |
|
|
31 |
|
-export([start_link/0, init/1]). |
32 |
|
-export([start_child/1, stop_child/1]). |
33 |
|
|
34 |
|
-include("mongoose_logger.hrl"). |
35 |
|
|
36 |
|
start_link() -> |
37 |
76 |
supervisor:start_link({local, ?MODULE}, ?MODULE, []). |
38 |
|
|
39 |
|
init([]) -> |
40 |
76 |
Hooks = |
41 |
|
{gen_hook, |
42 |
|
{gen_hook, start_link, []}, |
43 |
|
permanent, |
44 |
|
brutal_kill, |
45 |
|
worker, |
46 |
|
[gen_hook]}, |
47 |
76 |
Cleaner = |
48 |
|
{mongoose_cleaner, |
49 |
|
{mongoose_cleaner, start_link, []}, |
50 |
|
permanent, |
51 |
|
brutal_kill, |
52 |
|
worker, |
53 |
|
[mongoose_cleaner]}, |
54 |
76 |
Router = |
55 |
|
{ejabberd_router, |
56 |
|
{ejabberd_router, start_link, []}, |
57 |
|
permanent, |
58 |
|
brutal_kill, |
59 |
|
worker, |
60 |
|
[ejabberd_router]}, |
61 |
76 |
S2S = |
62 |
|
{ejabberd_s2s, |
63 |
|
{ejabberd_s2s, start_link, []}, |
64 |
|
permanent, |
65 |
|
brutal_kill, |
66 |
|
worker, |
67 |
|
[ejabberd_s2s]}, |
68 |
76 |
Local = |
69 |
|
{ejabberd_local, |
70 |
|
{ejabberd_local, start_link, []}, |
71 |
|
permanent, |
72 |
|
brutal_kill, |
73 |
|
worker, |
74 |
|
[ejabberd_local]}, |
75 |
76 |
Listener = |
76 |
|
{mongoose_listener_sup, |
77 |
|
{mongoose_listener_sup, start_link, []}, |
78 |
|
permanent, |
79 |
|
infinity, |
80 |
|
supervisor, |
81 |
|
[mongoose_listener_sup]}, |
82 |
76 |
ReceiverSupervisor = |
83 |
|
{ejabberd_receiver_sup, |
84 |
|
{ejabberd_tmp_sup, start_link, |
85 |
|
[ejabberd_receiver_sup, ejabberd_receiver]}, |
86 |
|
permanent, |
87 |
|
infinity, |
88 |
|
supervisor, |
89 |
|
[ejabberd_tmp_sup]}, |
90 |
76 |
C2SSupervisor = |
91 |
|
{ejabberd_c2s_sup, |
92 |
|
{ejabberd_tmp_sup, start_link, [ejabberd_c2s_sup, ejabberd_c2s]}, |
93 |
|
permanent, |
94 |
|
infinity, |
95 |
|
supervisor, |
96 |
|
[ejabberd_tmp_sup]}, |
97 |
76 |
S2SInSupervisor = |
98 |
|
{ejabberd_s2s_in_sup, |
99 |
|
{ejabberd_tmp_sup, start_link, |
100 |
|
[ejabberd_s2s_in_sup, ejabberd_s2s_in]}, |
101 |
|
permanent, |
102 |
|
infinity, |
103 |
|
supervisor, |
104 |
|
[ejabberd_tmp_sup]}, |
105 |
76 |
S2SOutSupervisor = |
106 |
|
{ejabberd_s2s_out_sup, |
107 |
|
{ejabberd_tmp_sup, start_link, |
108 |
|
[ejabberd_s2s_out_sup, ejabberd_s2s_out]}, |
109 |
|
permanent, |
110 |
|
infinity, |
111 |
|
supervisor, |
112 |
|
[ejabberd_tmp_sup]}, |
113 |
76 |
ServiceSupervisor = |
114 |
|
{ejabberd_service_sup, |
115 |
|
{ejabberd_tmp_sup, start_link, |
116 |
|
[ejabberd_service_sup, ejabberd_service]}, |
117 |
|
permanent, |
118 |
|
infinity, |
119 |
|
supervisor, |
120 |
|
[ejabberd_tmp_sup]}, |
121 |
76 |
OutgoingPoolsSupervisor = |
122 |
|
{mongoose_wpool_sup, |
123 |
|
{mongoose_wpool_sup, start_link, []}, |
124 |
|
permanent, infinity, |
125 |
|
supervisor, [mongoose_wpool_sup]}, |
126 |
76 |
IQSupervisor = |
127 |
|
{ejabberd_iq_sup, |
128 |
|
{ejabberd_tmp_sup, start_link, |
129 |
|
[ejabberd_iq_sup, mongoose_iq_worker]}, |
130 |
|
permanent, |
131 |
|
infinity, |
132 |
|
supervisor, |
133 |
|
[ejabberd_tmp_sup]}, |
134 |
76 |
SMBackendSupervisor = |
135 |
|
{ejabberd_sm_backend_sup, |
136 |
|
{ejabberd_sm_backend_sup, start_link, []}, |
137 |
|
permanent, |
138 |
|
infinity, |
139 |
|
supervisor, |
140 |
|
[ejabberd_sm_backend_sup]}, |
141 |
76 |
MucIQ = |
142 |
|
{mod_muc_iq, |
143 |
|
{mod_muc_iq, start_link, []}, |
144 |
|
permanent, |
145 |
|
brutal_kill, |
146 |
|
worker, |
147 |
|
[mod_muc_iq]}, |
148 |
76 |
ShaperSup = |
149 |
|
{ejabberd_shaper_sup, |
150 |
|
{ejabberd_shaper_sup, start_link, []}, |
151 |
|
permanent, infinity, supervisor, [ejabberd_shaper_sup]}, |
152 |
76 |
PG = |
153 |
|
{pg, |
154 |
|
{pg, start_link, [mim_scope]}, |
155 |
|
permanent, infinity, supervisor, [pg]}, |
156 |
76 |
{ok, {{one_for_one, 10, 1}, |
157 |
|
[PG, |
158 |
|
Hooks, |
159 |
|
Cleaner, |
160 |
|
SMBackendSupervisor, |
161 |
|
Router, |
162 |
|
S2S, |
163 |
|
Local, |
164 |
|
ReceiverSupervisor, |
165 |
|
C2SSupervisor, |
166 |
|
S2SInSupervisor, |
167 |
|
S2SOutSupervisor, |
168 |
|
ServiceSupervisor, |
169 |
|
OutgoingPoolsSupervisor, |
170 |
|
IQSupervisor, |
171 |
|
Listener, |
172 |
|
MucIQ, |
173 |
|
ShaperSup]}}. |
174 |
|
|
175 |
|
start_child(ChildSpec) -> |
176 |
845 |
case supervisor:start_child(ejabberd_sup, ChildSpec) of |
177 |
|
{ok, Pid} -> |
178 |
845 |
{ok, Pid}; |
179 |
|
Other -> |
180 |
:-( |
Stacktrace = element(2, erlang:process_info(self(), current_stacktrace)), |
181 |
:-( |
?LOG_ERROR(#{what => start_child_failed, spec => ChildSpec, |
182 |
:-( |
reason => Other, stacktrace => Stacktrace}), |
183 |
:-( |
erlang:error({start_child_failed, Other, ChildSpec}) |
184 |
|
end. |
185 |
|
|
186 |
|
stop_child(Proc) -> |
187 |
770 |
supervisor:terminate_child(ejabberd_sup, Proc), |
188 |
770 |
supervisor:delete_child(ejabberd_sup, Proc), |
189 |
770 |
ok. |