@cryptotaxi247 / infra / commits / d28ee659

Convert some cronjobs to systemd services

Eelco Dolstra committed Oct 3, 2016 at 16:01 UTC d28ee65919b8b07afe1910862edb5d3e9c60a911
2 files changed +60 -30
delft/sysstat.nix
+20 -4
@@ -2,8 +2,24 @@
2 {
3 environment.systemPackages = [ pkgs.sysstat ];
4
5 - services.cron.systemCronJobs =
6 - [ "*/1 * * * * root mkdir -p /var/log/sa; ${pkgs.sysstat}/lib/sa/sa1 -S DISK 1 1"
7 - "53 23 * * * root mkdir -p /var/log/sa; ${pkgs.sysstat}/lib/sa/sa2 -A"
8 - ];
5 + systemd.services.sa1 =
6 + { script =
7 + ''
8 + mkdir -p /var/log/sa
9 + exec ${pkgs.sysstat}/lib/sa/sa1 -S DISK 1 1
10 + '';
11 + serviceConfig.Type = "oneshot";
12 + startAt = "*:1";
13 + };
14 +
15 + systemd.services.sa2 =
16 + { path = [ pkgs.xz ];
17 + script =
18 + ''
19 + mkdir -p /var/log/sa
20 + exec ${pkgs.sysstat}/lib/sa/sa2 -A
21 + '';
22 + serviceConfig.Type = "oneshot";
23 + startAt = "23:53";
24 + };
25 }
delft/wendy.nix
+40 -26
@@ -2,27 +2,6 @@
2
3 with lib;
4
5 -let
6 - duplicityBackup = pkgs.writeScript "backup-duplicity" ''
7 - #! /bin/sh
8 - echo "Starting backups"
9 - export PATH=$PATH:/var/run/current-system/sw/bin
10 - time duplicity --full-if-older-than 30D --no-encryption /data/pt-wiki file:///backup/cartman/pt-wiki
11 - time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/pt-wiki
12 -
13 - time duplicity --full-if-older-than 30D --no-encryption /data/subversion file:///backup/cartman/subversion
14 - time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion
15 -
16 - time duplicity --full-if-older-than 30D --no-encryption /data/subversion-ptg file:///backup/cartman/subversion-ptg
17 - time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion-ptg
18 -
19 - time duplicity --full-if-older-than 30D --no-encryption /data/subversion-strategoxt file:///backup/cartman/subversion-strategoxt
20 - time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion-strategoxt
21 -
22 - echo Done
23 - '';
24 -
25 -in
5 {
6 imports = [ ./build-machines-dell-r815.nix ./delft-webserver.nix ./sysstat.nix ./datadog.nix ];
7
@@ -63,13 +42,39 @@ in
42 '';
43 };
44
45 + systemd.services.duplicity-backup =
46 + {
47 + path = [ pkgs.duplicity ];
48 +
49 + unitConfig.RequiresMountsFor = [ "/backup" ];
50 +
51 + script = ''
52 + export PATH=$PATH:/var/run/current-system/sw/bin
53 + time duplicity --full-if-older-than 30D --no-encryption /data/pt-wiki file:///backup/cartman/pt-wiki
54 + time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/pt-wiki
55 +
56 + time duplicity --full-if-older-than 30D --no-encryption /data/subversion file:///backup/cartman/subversion
57 + time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion
58 +
59 + time duplicity --full-if-older-than 30D --no-encryption /data/subversion-ptg file:///backup/cartman/subversion-ptg
60 + time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion-ptg
61 +
62 + time duplicity --full-if-older-than 30D --no-encryption /data/subversion-strategoxt file:///backup/cartman/subversion-strategoxt
63 + time duplicity --no-encryption --force remove-all-inc-of-but-n-full 1 file:///backup/cartman/subversion-strategoxt
64 + '';
65 +
66 + startAt = "02:40";
67 + };
68 +
69 + systemd.mounts =
70 + [ { mountConfig.TimeoutSec = 300;
71 + what = "130.161.158.5:/dxs/users4/group/buildfarm";
72 + where = "/backup";
73 + }
74 + ];
75 +
76 services.cron.systemCronJobs =
77 [ #"15 4 * * * root cp -v /var/backup/postgresql/* /backup/wendy/postgresql/ &> /var/log/backup-db.log"
68 - # Force the sixxs tunnel to stay alive by periodically
69 - # pinging the other side. This is necessary to remain
70 - # reachable from the outside.
71 - "*/10 * * * * root ${pkgs.iputils}/sbin/ping6 -c 1 2001:610:600:88d::1"
72 - "40 2 * * * root ${duplicityBackup} &>> /var/log/backup-duplicity.log"
78 ];
79
80 services.radvd.enable = false;
@@ -82,6 +87,15 @@ in
87 };
88 '';
89
90 + # Force the sixxs tunnel to stay alive by periodically
91 + # pinging the other side. This is necessary to remain
92 + # reachable from the outside.
93 + systemd.services.ping-sixxs =
94 + { serviceConfig.ExecStart = "${pkgs.iputils}/sbin/ping6 -c 1 2001:610:600:88d::1";
95 + serviceConfig.Type = "oneshot";
96 + startAt = "*:0/10";
97 + };
98 +
99 networking = {
100
101 firewall.allowedTCPPorts = [ 80 443 10051 5432 5999 ];