From e6ace2a76ad7195e77629ac6c4846747ce23985f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 27 Sep 2015 12:43:53 +0200 Subject: [PATCH] taskd service: Add initialization script --- nixos/modules/services/misc/taskserver.nix | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/misc/taskserver.nix b/nixos/modules/services/misc/taskserver.nix index d4948e39f9ea..ea79fae99f3a 100644 --- a/nixos/modules/services/misc/taskserver.nix +++ b/nixos/modules/services/misc/taskserver.nix @@ -191,7 +191,28 @@ in { after = [ "network.target" ]; preStart = '' - mkdir -p ${cfg.dataDir} + mkdir -p "${cfg.dataDir}" + + if [[ ! -e "${cfg.dataDir}/.is_initialized" ]] + then + ${pkgs.taskserver}/bin/taskd init + ${pkgs.taskserver}/pki/generate + for file in {{client,server}.{cert,key},server.crl,ca.cert} + do + cp $file.pem "${cfg.dataDir}/" + ${pkgs.taskserver}/bin/taskd config --force \ + $file "${cfg.dataDir}/$file.pem" + done + + ${pkgs.taskserver}/bin/taskd config --force log "${cfg.log}" + ${pkgs.taskserver}/bin/taskd config --force pid.file "${cfg.pidFile}" + ${pkgs.taskserver}/bin/taskd config --force server ${cfg.server.host}:${toString cfg.server.port} + + touch "${cfg.dataDir}/.is_initialized" + else + # already initialized + echo "Taskd was initialized. Not initializing again" + fi ''; environment = {