summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-03-01 13:32:04 +0100
committerMagnus Ahltorp <map@kth.se>2015-03-01 13:32:04 +0100
commit985fd30939e9901ea2c7f82d747e975d4e4ed50a (patch)
treee9262388ca5a6bee0d805a26098e5ed6bb8dfd2b /src
parent0aff0f752fd4a5d342fbb1a9a9192ae239f48b1f (diff)
Make sign and ht optional processes. Move sign args to config.
Diffstat (limited to 'src')
-rw-r--r--src/plop_sup.erl61
-rw-r--r--src/sign.erl10
2 files changed, 34 insertions, 37 deletions
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,