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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
%%% Copyright (c) 2014-2015, NORDUnet A/S.
%%% See LICENSE for licensing information.
-module(plop_sup).
-behaviour(supervisor).
-export([start_link/1, init/1]).
-export([start_in_shell/1]).
start_link(_Args) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%% For testing.
start_in_shell(Args) ->
{ok, Pid} = start_link(Args),
unlink(Pid).
permanent_worker(Name, {Module, Function, Args}) ->
permanent_worker(Name, {Module, Function, Args}, [Module]).
permanent_worker(Name, StartFunc, Modules) ->
{Name,
StartFunc,
permanent,
10000,
worker, Modules}.
database_children(DB) ->
lists:filtermap(fun ({Module, Name, DBName, ConfigName}) ->
case application:get_env(plop, ConfigName) of
{ok, Path} ->
{true, permanent_worker(Name, {Module, start_link, [DBName, Path]})};
undefined ->
false
end
end, DB).
%% Supervisor callback
init([]) ->
Services = application:get_env(plop, services, []),
DBChildren = database_children([
{perm, the_entryhash_db, entryhash_db, entryhash_root_path},
{perm, the_indexforhash_db, indexforhash_db, indexforhash_root_path},
{perm, the_entry_db, entry_db, entry_root_path},
{perm, the_sptcache, sptcache, sptcache_root_path},
{index, the_index_db, index_db, index_path},
{index, the_newentries_db, newentries_db, newentries_path}
]),
Children = [permanent_worker(the_db, {db, start_link, []}, [db]),
permanent_worker(the_storagedb, {storagedb, start_link, []}),
permanent_worker(fsync, {fsyncport, start_link, []}),
permanent_worker(the_statusreport, {statusreport, start_link, []}),
permanent_worker(plopcontrol, {plopcontrol, start_link, []})],
OptionalChildren = lists:map(fun (ServiceName) ->
case ServiceName of
ht ->
permanent_worker(the_ht, {ht, start_link, []});
sign ->
permanent_worker(the_signing, {sign, start_link, []})
end
end, Services),
{ok, {{one_for_one, 3, 10},
DBChildren ++ Children ++ OptionalChildren
}}.
|