%%% 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}, {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(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 }}.