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 ++++++++++++++++++++++++++------------------------------ src/sign.erl | 10 ++++++---- 2 files changed, 34 insertions(+), 37 deletions(-) (limited to 'src') 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 + }}. diff --git a/src/sign.erl b/src/sign.erl index eae76e7..2c4441b 100644 --- a/src/sign.erl +++ b/src/sign.erl @@ -7,7 +7,7 @@ -behaviour(gen_server). %% API. --export([start_link/2, stop/0]). +-export([start_link/0, stop/0]). -export([sign/1, get_pubkey/0, get_logid/0]). -export([read_keyfile_ec/1]). %% API for tests. @@ -26,19 +26,21 @@ logid :: binary() }). -start_link(Keyfile, Passphrase) -> - gen_server:start_link({local, ?MODULE}, ?MODULE, [Keyfile, Passphrase], []). +start_link() -> + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). stop() -> call(?MODULE, stop). -init([PrivKeyfile, PubKeyfile]) -> +init([]) -> %% Read RSA keypair. %% {Private_key, Public_key} = read_keyfile_rsa(Keyfile, Passphrase), %% LogID = crypto:hash(sha256, %% public_key:der_encode('RSAPublicKey', Public_key)), %% Read EC keypair. + PrivKeyfile = application:get_env(plop, log_private_key, none), + PubKeyfile = application:get_env(plop, log_public_key, none), {Private_key, Public_key, LogID} = read_keyfiles_ec(PrivKeyfile, PubKeyfile), _Tree = ht:reset_tree([db:size() - 1]), {ok, #state{pubkey = Public_key, -- cgit v1.1