summaryrefslogtreecommitdiff
path: root/src/catlfish_sup.erl
blob: 882a017b8eb9dbc671aab2de330b34b7b2ba714c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%%% Copyright (c) 2014, NORDUnet A/S.
%%% See LICENSE for licensing information.

-module(catlfish_sup).
-behaviour(supervisor).

-export([start_link/1, init/1]).

start_link(_Args) ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

gen_http_config(Config, SSLOptions, SSLFlag) ->
    {ChildName, IpAddress, Port, Module} = Config,
    {ok, IPv4Address} =
        inet:parse_ipv4strict_address(IpAddress),
    WebConfig = [{ip, IPv4Address},
                 {port, Port},
                 {ssl, SSLFlag},
                 {acceptor_pool_size, application:get_env(catlfish, http_server_pool_size, 16)},
                 {ssl_opts, SSLOptions}
                ],
    {ChildName,
     {catlfish_web, start, [WebConfig, Module, ChildName]},
                           permanent, 5000,
     worker, dynamic}.

init([]) ->
    SSLOptions =
        [{certfile, application:get_env(catlfish, https_certfile, none)},
         {keyfile, application:get_env(catlfish, https_keyfile, none)},
         {cacertfile, application:get_env(catlfish, https_cacertfile, none)}],
    Servers =
        lists:map(fun (Config) ->
                          gen_http_config(Config, SSLOptions, true)
                  end, application:get_env(catlfish, https_servers, [])) ++
        lists:map(fun (Config) ->
                          gen_http_config(Config, SSLOptions, false)
                  end, application:get_env(catlfish, http_servers, [])),
    lager:debug("Starting servers ~p", [Servers]),
    {ok,
     {{one_for_one, 3, 10},
      Servers}}.