@cryptotaxi247 / infra-1 / commits / b3a56447

* Now really update jobs to systemd.

svn path=/configurations/trunk/tud/; revision=34641

Eelco Dolstra committed Oct 29, 2012 at 11:28 UTC b3a5644703be2ca8454d5917237fbdd6e9323791
3 files changed +126 -114
cartman.nix
+3 -24
@@ -674,28 +674,7 @@ rec {
674 };
675
676 # Use cgroups to limit Apache's resources.
677 - services.cgroups.enable = true;
678 -
679 - services.cgroups.groups =
680 - ''
681 - mount {
682 - cpu = /sys/fs/cgroup/cpu;
683 - memory = /sys/fs/cgroup/memory;
684 - }
685 -
686 - group httpd {
687 - cpu {
688 - cpu.shares = "1000";
689 - }
690 - memory {
691 - memory.limit_in_bytes = "1500M";
692 - memory.memsw.limit_in_bytes = "1500M";
693 - }
694 - }
695 - '';
696 -
697 - services.cgroups.rules =
698 - ''
699 - wwwrun:httpd cpu,memory httpd
700 - '';
677 + boot.systemd.services.httpd.serviceConfig.CPUShares = 1000;
678 + boot.systemd.services.httpd.serviceConfig.MemoryLimit = "1500M";
679 + boot.systemd.services.httpd.serviceConfig.ControlGroupAttribute = [ "memory.memsw.limit_in_bytes 1500M" ];
680 }
hydra-module.nix
+84 -48
@@ -3,18 +3,32 @@
3 with pkgs.lib;
4
5 let
6 +
7 cfg = config.services.hydra;
8
8 - hydraConf = pkgs.writeScript "hydra.conf"
9 + hydra = "/home/hydra/.nix-profile"; # FIXME
10 +
11 + hydraConf = pkgs.writeScript "hydra.conf"
12 ''
13 using_frontend_proxy 1
14 base_uri ${cfg.hydraURL}
15 notification_sender ${cfg.notificationSender}
16 max_servers 50
17 '';
15 -
16 - env = ''NIX_REMOTE=daemon HYDRA_DBI="${cfg.dbi}" HYDRA_CONFIG=${cfg.baseDir}/data/hydra.conf HYDRA_DATA=${cfg.baseDir}/data '';
17 - server_env = env + ''HYDRA_LOGO="${cfg.logo}" HYDRA_TRACKER="${cfg.tracker}" '';
18 +
19 + env =
20 + { NIX_REMOTE = "daemon";
21 + HYDRA_DBI = cfg.dbi;
22 + HYDRA_CONFIG = "${cfg.baseDir}/data/hydra.conf";
23 + HYDRA_DATA = "${cfg.baseDir}/data";
24 + #HOME = "/home/hydra";
25 + OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
26 + };
27 +
28 + serverEnv = env //
29 + { HYDRA_LOGO = cfg.logo;
30 + #HYDRA_TRACKER = cfg.tracker; # FIXME: needs escaping (or should be read from a file)
31 + };
32
33 in
34
@@ -22,8 +36,9 @@ in
36 ###### interface
37
38 options = {
39 +
40 services.hydra = rec {
26 -
41 +
42 enable = mkOption {
43 default = false;
44 description = ''
@@ -44,60 +59,60 @@ in
59 The user the Hydra services should run as.
60 '';
61 };
47 -
62 +
63 dbi = mkOption {
64 default = "dbi:Pg:dbname=hydra;host=wendy;user=hydra;";
65 description = ''
66 The DBI string for Hydra database connection
67 '';
68 };
54 -
69 +
70 hydraURL = mkOption {
71 default = "http://hydra.nixos.org";
72 description = ''
58 - The base URL for the Hydra webserver instance. Used for links in emails.
73 + The base URL for the Hydra webserver instance. Used for links in emails.
74 '';
75 };
61 -
76 +
77 minimumDiskFree = mkOption {
78 default = 5;
79 description = ''
65 - Threshold of minimum disk space (G) to determine if queue runner should run or not.
80 + Threshold of minimum disk space (GiB) to determine if queue runner should run or not.
81 '';
82 };
83
84 minimumDiskFreeEvaluator = mkOption {
85 default = 2;
86 description = ''
72 - Threshold of minimum disk space (G) to determine if evaluator should run or not.
87 + Threshold of minimum disk space (GiB) to determine if evaluator should run or not.
88 '';
89 };
90
91 notificationSender = mkOption {
92 default = "e.dolstra@tudelft.nl";
93 description = ''
79 - Sender email address used for email notifications.
94 + Sender email address used for email notifications.
95 '';
81 - };
96 + };
97
98 tracker = mkOption {
99 default = "";
100 description = ''
101 Piece of HTML that is included on all pages.
102 '';
88 - };
89 -
103 + };
104 +
105 logo = mkOption {
106 default = "";
107 description = ''
108 Path to a file containing the logo of your Hydra instance.
109 '';
95 - };
96 -
110 + };
111 +
112 };
113
114 };
100 -
115 +
116
117 ###### implementation
118
@@ -109,7 +124,7 @@ in
124 home = cfg.baseDir;
125 createHome = true;
126 useDefaultShell = true;
112 - }
127 + }
128 ];
129
130 nix.maxJobs = 0;
@@ -117,10 +132,10 @@ in
132 nix.manualNixMachines = true;
133 nix.useChroot = true;
134 nix.nrBuildUsers = 100;
120 -
135 +
136 nix.gc.automatic = true;
137 nix.gc.options = ''--max-freed "$((400 * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | awk '{ print $4 }')))"'';
123 -
138 +
139 nix.extraOptions = ''
140 gc-keep-outputs = true
141 gc-keep-derivations = true
@@ -136,8 +151,7 @@ in
151 '';
152
153 jobs."hydra-init" =
139 - { name = "hydra-init";
140 - startOn = "filesystem";
154 + { wantedBy = [ "multi-user.target" ];
155 script = ''
156 mkdir -p ${cfg.baseDir}/data
157 chown ${cfg.user} ${cfg.baseDir}/data
@@ -146,29 +160,52 @@ in
160 task = true;
161 };
162
149 - jobs."hydra-server" =
150 - { name = "hydra-server";
151 - startOn = "started network-interfaces and started hydra-init";
152 - exec = ''
153 - ${pkgs.su}/bin/su - ${cfg.user} -c '${server_env} exec hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100 > ${cfg.baseDir}/data/server.log 2>&1'
154 - '';
163 + boot.systemd.services."hydra-server" =
164 + { wantedBy = [ "multi-user.target" ];
165 + wants = [ "hydra-init.service" ];
166 + after = [ "hydra-init.service" ];
167 + environment = serverEnv;
168 + serviceConfig =
169 + { ExecStart = "@${hydra}/bin/hydra-server hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100";
170 + User = cfg.user;
171 + Restart = "always";
172 + };
173 };
174
157 - jobs."hydra-queue-runner" =
158 - { name = "hydra-queue-runner";
159 - startOn = "started network-interfaces and started hydra-init";
160 - preStart = "${pkgs.su}/bin/su - ${cfg.user} -c '${env} hydra-queue-runner --unlock'";
161 - exec = ''
162 - ${pkgs.su}/bin/su - ${cfg.user} -c '${env} exec hydra-queue-runner > ${cfg.baseDir}/data/queue_runner.log 2>&1'
163 - '';
175 + boot.systemd.services."hydra-queue-runner" =
176 + { wantedBy = [ "multi-user.target" ];
177 + wants = [ "hydra-init.service" ];
178 + after = [ "hydra-init.service" "network.target" ];
179 + environment = env;
180 + serviceConfig =
181 + { ExecStartPre = "${hydra}/bin/hydra-queue-runner --unlock";
182 + ExecStart = "@${hydra}/bin/hydra-queue-runner hydra-queue-runner";
183 + User = cfg.user;
184 + Restart = "always";
185 + };
186 };
187
166 - jobs."hydra-evaluator" =
167 - { name = "hydra-evaluator";
168 - startOn = "started network-interfaces";
169 - exec = ''
170 - ${pkgs.su}/bin/su - ${cfg.user} -c '${env} exec hydra-evaluator > ${cfg.baseDir}/data/evaluator.log 2>&1'
171 - '';
188 + boot.systemd.services."hydra-evaluator" =
189 + { wantedBy = [ "multi-user.target" ];
190 + wants = [ "hydra-init.service" ];
191 + after = [ "hydra-init.service" "network.target" ];
192 + path = [ pkgs.nettools ];
193 + environment = env;
194 + serviceConfig =
195 + { ExecStart = "@${hydra}/bin/hydra-evaluator hydra-evaluator";
196 + User = cfg.user;
197 + Restart = "always";
198 + };
199 + };
200 +
201 + boot.systemd.services."hydra-update-gc-roots" =
202 + { wants = [ "hydra-init.service" ];
203 + after = [ "hydra-init.service" ];
204 + environment = env;
205 + serviceConfig =
206 + { ExecStart = "@${hydra}/bin/hydra-update-gc-roots hydra-update-gc-roots";
207 + User = cfg.user;
208 + };
209 };
210
211 services.cron.systemCronJobs =
@@ -185,18 +222,17 @@ in
222 stop hydra-evaluator
223 fi
224 '';
188 - compressLogs = pkgs.writeScript "compress-logs"
225 + compressLogs = pkgs.writeScript "compress-logs"
226 ''
227 #! /bin/sh -e
228 touch -d 'last month' r
229 find /nix/var/log/nix/drvs -type f -a ! -newer r -name '*.drv' | xargs bzip2 -v
230 '';
231 in
195 - [ "*/5 * * * * root ${checkSpace} &> ${cfg.baseDir}/data/checkspace.log"
196 - "15 5 * * * root ${compressLogs} &> ${cfg.baseDir}/data/compress.log"
197 - "15 02 * * * ${cfg.user} ${env} /home/${cfg.user}/.nix-profile/bin/hydra-update-gc-roots &> ${cfg.baseDir}/data/gc-roots.log"
232 + [ "*/5 * * * * root ${checkSpace} &> ${cfg.baseDir}/data/checkspace.log"
233 + "15 5 * * * root ${compressLogs} &> ${cfg.baseDir}/data/compress.log"
234 + "15 2 * * * root ${pkgs.systemd}/bin/systemctl start hydra-update-gc-roots.service"
235 ];
236
200 - };
237 + };
238 }
202 -
lucifer.nix
+39 -42
@@ -84,29 +84,6 @@
84 cpu = /dev/cgroup/cpu;
85 blkio = /dev/cgroup/blkio;
86 }
87 - group sshd {
88 - cpu {
89 - cpu.shares = "2000";
90 - }
91 - }
92 - group hydra-server {
93 - cpu {
94 - cpu.shares = "700";
95 - }
96 - }
97 - group hydra-build {
98 - cpu {
99 - cpu.shares = "200";
100 - }
101 - blkio {
102 - blkio.weight = "500";
103 - }
104 - }
105 - group hydra-evaluator {
106 - cpu {
107 - cpu.shares = "100";
108 - }
109 - }
87 group hydra-mirror {
88 cpu {
89 cpu.shares = "100";
@@ -115,52 +92,72 @@
92 '';
93 rules =
94 ''
118 - root:sshd cpu sshd
119 - root:nix-worker cpu,blkio hydra-build
120 - root:build-remote.pl cpu,blkio hydra-build
121 - hydra:nix-store cpu,blkio hydra-build
122 - hydra:.hydra-build-wrapped cpu,blkio hydra-build
123 - hydra:.hydra-evaluator-wrapped cpu hydra-evaluator
124 - hydra:.hydra-server-wrapped cpu hydra-server
95 hydra-mirror cpu hydra-mirror
96 '';
97 };
98 */
99
130 - jobs."mirror-nixpkgs" =
131 - { startOn = "started networking";
100 + # Set some cgroup limits.
101 + boot.systemd.services.sshd.serviceConfig.CPUShares = 2000;
102 + boot.systemd.services.nix-daemon.serviceConfig.CPUShares = 200;
103 + boot.systemd.services.nix-daemon.serviceConfig.BlockIOWeight = 500;
104 + boot.systemd.services.hydra-queue-runner.serviceConfig.CPUShares = 200;
105 + boot.systemd.services.hydra-evaluator.serviceConfig.CPUShares = 100;
106 + boot.systemd.services.hydra-server.serviceConfig.CPUShares = 700;
107 +
108 + boot.systemd.services.mirror-nixpkgs =
109 + { description = "Mirror Nixpkgs";
110 + wantedBy = [ "multi-user.target" ];
111 + after = [ "networking.target" ];
112 path = [ pkgs.su ];
113 script =
114 ''
135 - su - hydra-mirror -c 'exec >> nixpkgs-mirror.log 2>&1; rm -rf /data/releases/nixpkgs/.tmp-*; cd release/channels; while true; do date; ./mirror-nixpkgs.sh; sleep 300; done'
115 + rm -rf /data/releases/nixpkgs/.tmp-*
116 + exec su - hydra-mirror -c 'cd release/channels; exec ./mirror-nixpkgs.sh'
117 '';
118 + serviceConfig.Restart = "always";
119 + serviceConfig.RestartSec = 300;
120 + serviceConfig.CPUShares = 100;
121 };
122
139 - jobs."generate-nixpkgs-patches" =
140 - { startOn = "started networking";
123 + boot.systemd.services.generate-nixpkgs-patches =
124 + { description = "Generate Nixpkgs Patches";
125 + wantedBy = [ "multi-user.target" ];
126 path = [ pkgs.su ];
127 script =
128 ''
144 - su - hydra-mirror -c 'exec >> nixpkgs-patches.log 2>&1; cd release/channels; while true; do date; ./generate-linear-patch-sequence.sh; sleep 300; done'
129 + exec su - hydra-mirror -c 'cd release/channels; exec ./generate-linear-patch-sequence.sh'
130 '';
131 + serviceConfig.Restart = "always";
132 + serviceConfig.RestartSec = 300;
133 + serviceConfig.CPUShares = 100;
134 };
135
148 - jobs."mirror-nixos" =
149 - { startOn = "started networking";
136 + boot.systemd.services.mirror-nixos =
137 + { description = "Mirror NixOS";
138 + wantedBy = [ "multi-user.target" ];
139 + after = [ "networking.target" ];
140 path = [ pkgs.su ];
141 script =
142 ''
153 - su - hydra-mirror -c 'exec >> nixos-mirror.log 2>&1; rm -rf /data/releases/nixos/.tmp-*; cd release/channels; while true; do date; ./mirror-nixos.sh; sleep 300; done'
143 + rm -rf /data/releases/nixos/.tmp-*
144 + exec su - hydra-mirror -c 'cd release/channels; exec ./mirror-nixos.sh'
145 '';
146 + serviceConfig.Restart = "always";
147 + serviceConfig.RestartSec = 300;
148 + serviceConfig.CPUShares = 100;
149 };
150
157 - jobs."convert-to-binary-channel" =
158 - { startOn = "started networking";
151 + boot.systemd.services.convert-to-binary-cache =
152 + { wantedBy = [ "multi-user.target" ];
153 path = [ pkgs.su ];
154 script =
155 ''
162 - su - hydra-mirror -c 'exec >> convert-to-binary-channel.log 2>&1; cd release/channels; while true; do date; ./convert-to-binary-channel.pl; sleep 3600; done'
156 + exec su - hydra-mirror -c 'cd release/channels; exec ./convert-to-binary-cache.pl'
157 '';
158 + serviceConfig.Restart = "always";
159 + serviceConfig.RestartSec = 3600;
160 + serviceConfig.CPUShares = 100;
161 };
162
163 }