%%% 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}. %% Supervisor callback init([]) -> Services = application:get_env(plop, services, []), Children = [permanent_worker(the_db, {db, start_link, []}, [db]), permanent_worker(the_storagedb, {storagedb, start_link, []}), permanent_worker(fsync, {fsyncport, 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}, Children ++ OptionalChildren }}.