PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 1ms 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. -behaviour(supervisor).
  20. -include("uce.hrl").
  21. % External API
  22. -export([start_link/0, name/2]).
  23. % Supervisor API
  24. -export([init/1]).
  25. name(Domain, Server) ->
  26. list_to_atom(lists:concat([Server, "_", Domain])).
  27. start_link() ->
  28. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  29. init([]) ->
  30. Hosts = config:get(hosts),
  31. Vhosts = vhost_supervise(Hosts),
  32. {ok, {{one_for_one, 10, 10}, Vhosts}}.
  33. vhost_supervise([]) ->
  34. [];
  35. vhost_supervise([{Domain, _HostConfig}|R]) ->
  36. [{name(Domain, "vhost"),
  37. {uce_vhost, start_link, [Domain]},
  38. permanent, brutal_kill, worker, [uce_vhost]},
  39. {name(Domain, "presence"),
  40. {uce_vhost_user_sup, start_link, [Domain]},
  41. permanent, brutal_kill, supervisor, [uce_vhost_user_sup]}] ++ vhost_supervise(R).
  42. %%
  43. %% Tests
  44. %%
  45. -ifdef(TEST).
  46. -include_lib("eunit/include/eunit.hrl").
  47. name_test() ->
  48. ?assertEqual(vhost_localhost, name(localhost, "vhost")),
  49. ?assertEqual('vhost_example.com', name('example.com', "vhost")).
  50. -endif.