Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created August 19, 2019 17:23
Show Gist options
  • Save grahamc/5c6cf5a2c40b1687c7e4d06a3e15e1fe to your computer and use it in GitHub Desktop.
Save grahamc/5c6cf5a2c40b1687c7e4d06a3e15e1fe to your computer and use it in GitHub Desktop.
{ pkgs , ... }:
{
systemd.services.run-vm = {
enable = true;
wants = [ "healthcheck-vm.timer" ];
before = [ "healthcheck-vm.timer" ];
script = ''
while true; do
echo "I'm up! :)"
sleep 10
done
'';
};
systemd.timers.healthcheck-vm = {
enable = true;
description = "Verify the VM is listening";
partOf = [ "run-vm.service"];
timerConfig = {
OnActiveSec = 900;
OnCalendar = "hourly";
Unit = "healthcheck-vm.service";
Persistent = "yes";
};
};
systemd.services.healthcheck-vm = {
enable = true;
script = ''
if [[ $(($RANDOM % 2)) -eq 0 ]]; then
echo "up!"
else
systemctl restart run-vm.service
fi
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment