@cryptotaxi247 / infra-1 / commits / 47d26b22

mac VMs: add a healthcheck timer

Eelco Dolstra committed Aug 19, 2019 at 19:37 UTC 47d26b22928a87ca3610034d226a4ad68bd17da5
1 file changed +28 -1
macs/host/qemu.nix
+28 -1
@@ -30,7 +30,8 @@ in {
30 requires = [ "create-macos-secrets.service" "dhcpd4.service" "kresd.service" "network-online.target" ];
31 after = requires;
32 wantedBy = [ "multi-user.target" ];
33 - wants = [ "netcatsyslog.service" ];
33 + wants = [ "netcatsyslog.service" "healthcheck-macos-vm.timer" ];
34 + before = [ "healthcheck-macos-vm.timer" ];
35 path = with pkgs; [ zfs qemu cdrkit rsync findutils ];
36
37 serviceConfig.PrivateTmp = true;
@@ -71,5 +72,31 @@ in {
72 -no-reboot
73 '';
74 };
75 +
76 + systemd.timers.healthcheck-macos-vm = {
77 + enable = true;
78 + description = "Verify the macOS VM is listening";
79 + partOf = [ "run-macos-vm.service"];
80 +
81 + timerConfig = {
82 + OnActiveSec = 900;
83 + OnCalendar = "hourly";
84 + Unit = "healthcheck-macos-vm.service";
85 + Persistent = "yes";
86 + };
87 + };
88 +
89 + systemd.services.healthcheck-macos-vm = {
90 + enable = true;
91 +
92 + script = ''
93 + if ${pkgs.curl}/bin/curl ${config.macosGuest.network.interiorNetworkPrefix}.2 > /dev/null; then
94 + echo "Appears to be up!"
95 + else
96 + echo "Appears to be down, restarting run-macos-vm"
97 + systemctl restart run-macos-vm.service
98 + fi
99 + '';
100 + };
101 };
102 }