Ported/merged properties from the TUD configuration's hydra-module
This commit is contained in:
parent
f4ae655ee6
commit
d8e2dfc0ed
139
hydra-module.nix
139
hydra-module.nix
|
@ -13,16 +13,19 @@ let
|
|||
max_servers 25
|
||||
'';
|
||||
|
||||
env = ''export NIX_REMOTE=daemon ''
|
||||
+ ''HYDRA_DBI="${cfg.dbi}" ''
|
||||
+ ''HYDRA_CONFIG=${cfg.baseDir}/data/hydra.conf ''
|
||||
+ ''HYDRA_DATA=${cfg.baseDir}/data ''
|
||||
+ ''HYDRA_PORT="${toString cfg.port}" ''
|
||||
+ (if cfg.logo != null
|
||||
then ''HYDRA_LOGO="${cfg.logo}" ''
|
||||
else "")
|
||||
+ ''HYDRA_TRACKER="${cfg.tracker}" ;'';
|
||||
|
||||
env =
|
||||
{ NIX_REMOTE = "daemon";
|
||||
HYDRA_DBI = cfg.dbi;
|
||||
HYDRA_CONFIG = "${cfg.baseDir}/data/hydra.conf";
|
||||
HYDRA_DATA = "${cfg.baseDir}/data";
|
||||
HYDRA_PORT = "${toString cfg.port}";
|
||||
OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
||||
};
|
||||
|
||||
serverEnv = env //
|
||||
{ HYDRA_LOGO = if cfg.logo != null then cfg.logo else "";
|
||||
HYDRA_TRACKER = cfg.tracker;
|
||||
};
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -60,7 +63,7 @@ in
|
|||
};
|
||||
|
||||
hydra = mkOption {
|
||||
default = pkgs.hydra;
|
||||
#default = pkgs.hydra;
|
||||
description = ''
|
||||
Location of hydra
|
||||
'';
|
||||
|
@ -121,6 +124,13 @@ in
|
|||
If hydra upstart jobs should start automatically.
|
||||
'';
|
||||
};
|
||||
|
||||
useWAL = mkOption {
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to use SQLite's Write-Ahead Logging, which may improve performance.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
@ -156,46 +166,71 @@ in
|
|||
build-cache-failure = true
|
||||
|
||||
build-poll-interval = 10
|
||||
|
||||
# Online log compression makes it impossible to get the tail of
|
||||
# builds that are in progress.
|
||||
build-compress-log = false
|
||||
|
||||
use-sqlite-wal = false
|
||||
use-sqlite-wal = ${if cfg.useWAL then "true" else "false"}
|
||||
'';
|
||||
|
||||
jobs.hydra_init =
|
||||
{ description = "hydra-init";
|
||||
startOn = "started network-interfaces";
|
||||
preStart = ''
|
||||
jobs."hydra-init" =
|
||||
{ wantedBy = [ "multi-user.target" ];
|
||||
script = ''
|
||||
mkdir -p ${cfg.baseDir}/data
|
||||
chown ${cfg.user} ${cfg.baseDir}/data
|
||||
ln -sf ${hydraConf} ${cfg.baseDir}/data/hydra.conf
|
||||
'';
|
||||
exec = ''
|
||||
echo done
|
||||
'';
|
||||
task = true;
|
||||
};
|
||||
|
||||
systemd.services."hydra-server" =
|
||||
{ wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "hydra-init.service" ];
|
||||
after = [ "hydra-init.service" ];
|
||||
environment = serverEnv;
|
||||
serviceConfig =
|
||||
{ ExecStart = "@${cfg.hydra}/bin/hydra-server hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100";
|
||||
User = cfg.user;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
|
||||
jobs.hydra_server =
|
||||
{ description = "hydra-server";
|
||||
startOn = if cfg.autoStart then "started network-interfaces hydra-init" else "never";
|
||||
exec = ''
|
||||
${pkgs.su}/bin/su - ${cfg.user} -c '${env} ${cfg.hydra}/bin/hydra-server > ${cfg.baseDir}/data/server.log 2>&1'
|
||||
'';
|
||||
systemd.services."hydra-queue-runner" =
|
||||
{ wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "hydra-init.service" ];
|
||||
after = [ "hydra-init.service" "network.target" ];
|
||||
path = [ pkgs.nettools pkgs.ssmtp ];
|
||||
environment = env;
|
||||
serviceConfig =
|
||||
{ ExecStartPre = "${cfg.hydra}/bin/hydra-queue-runner --unlock";
|
||||
ExecStart = "@${cfg.hydra}/bin/hydra-queue-runner hydra-queue-runner";
|
||||
User = cfg.user;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
|
||||
jobs.hydra_queue_runner =
|
||||
{ description = "hydra-queue-runner";
|
||||
startOn = if cfg.autoStart then "started network-interfaces hydra-init" else "never";
|
||||
preStart = "${pkgs.su}/bin/su - ${cfg.user} -c '${env} ${cfg.hydra}/bin/hydra-queue-runner --unlock'";
|
||||
exec = ''
|
||||
${pkgs.su}/bin/su - ${cfg.user} -c '${env} nice -n 8 ${cfg.hydra}/bin/hydra-queue-runner > ${cfg.baseDir}/data/queue-runner.log 2>&1'
|
||||
'';
|
||||
systemd.services."hydra-evaluator" =
|
||||
{ wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "hydra-init.service" ];
|
||||
after = [ "hydra-init.service" "network.target" ];
|
||||
path = [ pkgs.nettools pkgs.ssmtp ];
|
||||
environment = env;
|
||||
serviceConfig =
|
||||
{ ExecStart = "@${cfg.hydra}/bin/hydra-evaluator hydra-evaluator";
|
||||
User = cfg.user;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
|
||||
jobs.hydra_evaluator =
|
||||
{ description = "hydra-evaluator";
|
||||
startOn = if cfg.autoStart then "started network-interfaces hydra-init" else "never";
|
||||
exec = ''
|
||||
${pkgs.su}/bin/su - ${cfg.user} -c '${env} nice -n 5 ${cfg.hydra}/bin/hydra-evaluator > ${cfg.baseDir}/data/evaluator.log 2>&1'
|
||||
'';
|
||||
systemd.services."hydra-update-gc-roots" =
|
||||
{ wants = [ "hydra-init.service" ];
|
||||
after = [ "hydra-init.service" ];
|
||||
environment = env;
|
||||
serviceConfig =
|
||||
{ ExecStart = "@${cfg.hydra}/bin/hydra-update-gc-roots hydra-update-gc-roots";
|
||||
User = cfg.user;
|
||||
};
|
||||
};
|
||||
|
||||
services.cron.systemCronJobs =
|
||||
|
@ -206,23 +241,11 @@ in
|
|||
''
|
||||
#! /bin/sh
|
||||
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
|
||||
stop hydra_queue_runner
|
||||
stop hydra_queue_runner
|
||||
fi
|
||||
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
|
||||
stop hydra_evaluator
|
||||
fi
|
||||
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
|
||||
stop hydra_evaluator
|
||||
fi
|
||||
'';
|
||||
|
||||
collect = pkgs.writeScript "collect-some-garbage"
|
||||
# Arrange to always have at least 100 GiB free.
|
||||
'' #!/bin/sh -e
|
||||
available="$(df -B1 /nix/store | tail -n 1 | awk '{ print $4 }')"
|
||||
target="$((100 * 1024**3))"
|
||||
to_free="$(($available > $target ? 200 * 1024**2 : $target - $available))"
|
||||
|
||||
echo "$available B available, and targeting $target B available"
|
||||
echo "thus, freeing $to_free B"
|
||||
exec "${pkgs.nix}/bin/nix-collect-garbage" --max-freed "$to_free"
|
||||
'';
|
||||
|
||||
compressLogs = pkgs.writeScript "compress-logs" ''
|
||||
|
@ -231,13 +254,9 @@ in
|
|||
find /nix/var/log/nix/drvs -type f -a ! -newer r -name '*.drv' | xargs bzip2 -v
|
||||
'';
|
||||
in
|
||||
[ "15 03 * * * root ${collect} &> ${cfg.baseDir}/data/gc.log"
|
||||
"15 13 * * * root ${collect} &> ${cfg.baseDir}/data/gc.log"
|
||||
|
||||
"*/5 * * * * root ${checkSpace} &> ${cfg.baseDir}/data/checkspace.log"
|
||||
|
||||
[ "*/5 * * * * root ${checkSpace} &> ${cfg.baseDir}/data/checkspace.log"
|
||||
"15 5 * * * root ${compressLogs} &> ${cfg.baseDir}/data/compress.log"
|
||||
"15 02 * * * ${cfg.user} ${env} ${cfg.hydra}/bin/hydra-update-gc-roots &> ${cfg.baseDir}/data/gc-roots.log"
|
||||
"15 2 * * * root ${pkgs.systemd}/bin/systemctl start hydra-update-gc-roots.service"
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue