From 985fd30939e9901ea2c7f82d747e975d4e4ed50a Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Sun, 1 Mar 2015 13:32:04 +0100 Subject: Make sign and ht optional processes. Move sign args to config. --- src/plop_sup.erl | 61 ++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'src/plop_sup.erl') diff --git a/src/plop_sup.erl b/src/plop_sup.erl index eb65925..c125cc0 100644 --- a/src/plop_sup.erl +++ b/src/plop_sup.erl @@ -7,44 +7,39 @@ -export([start_link/1, init/1]). -export([start_in_shell/1]). -start_link(Args) -> - supervisor:start_link({local, ?MODULE}, ?MODULE, Args). +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(Args) -> +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}, - [{the_db, - {db, start_link, []}, - permanent, - 10000, - worker, [db]}, - {the_storagedb, - {storagedb, start_link, []}, - permanent, - 10000, - worker, [storagedb]}, - {fsync, - {fsyncport, start_link, []}, - permanent, - 10000, - worker, [fsyncport]}, - {the_ht, - {ht, start_link, []}, - permanent, - 10000, - worker, [ht]}, - {the_signing, - {sign, start_link, Args}, % All arguments go to sign. - permanent, - 10000, - worker, [sign]}, - {the_plop, - {plop, start_link, []}, - permanent, - 10000, % Shut down within 10s. - worker, [plop]}]}}. + Children ++ OptionalChildren + }}. -- cgit v1.1