Created
August 19, 2019 17:23
-
-
Save grahamc/5c6cf5a2c40b1687c7e4d06a3e15e1fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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