PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/ucengine/src/core/uce_vhost_sup.erl

http://github.com/AF83/ucengine
Erlang | 62 lines | 28 code | 12 blank | 22 comment | 0 complexity | f0c7e8e408b677a3561c22f3ad677f3c MD5 | raw file
 1%%
 2%%  U.C.Engine - Unified Collaboration Engine
 3%%  Copyright (C) 2011 af83
 4%%
 5%%  This program is free software: you can redistribute it and/or modify
 6%%  it under the terms of the GNU Affero General Public License as published by
 7%%  the Free Software Foundation, either version 3 of the License, or
 8%%  (at your option) any later version.
 9%%
10%%  This program is distributed in the hope that it will be useful,
11%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
12%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13%%  GNU Affero General Public License for more details.
14%%
15%%  You should have received a copy of the GNU Affero General Public License
16%%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17%%
18-module(uce_vhost_sup).
19
20-behaviour(supervisor).
21
22-include("uce.hrl").
23
24% External API
25-export([start_link/0, name/2]).
26% Supervisor API
27-export([init/1]).
28
29name(Domain, Server) ->
30    list_to_atom(lists:concat([Server, "_", Domain])).
31
32start_link() ->
33    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
34
35init([]) ->
36    Hosts = config:get(hosts),
37    Vhosts = vhost_supervise(Hosts),
38    {ok, {{one_for_one, 10, 10}, Vhosts}}.
39
40vhost_supervise([]) ->
41    [];
42vhost_supervise([{Domain, _HostConfig}|R]) ->
43    [{name(Domain, "vhost"),
44      {uce_vhost, start_link, [Domain]},
45      permanent, brutal_kill, worker, [uce_vhost]},
46    {name(Domain, "presence"),
47     {uce_vhost_user_sup, start_link, [Domain]},
48     permanent, brutal_kill, supervisor, [uce_vhost_user_sup]}] ++ vhost_supervise(R).
49
50
51%%
52%% Tests
53%%
54
55-ifdef(TEST).
56-include_lib("eunit/include/eunit.hrl").
57
58name_test() ->
59    ?assertEqual(vhost_localhost, name(localhost, "vhost")),
60    ?assertEqual('vhost_example.com', name('example.com', "vhost")).
61
62-endif.