os/hosts/droppie/restic-backup.nix
Benjamin Bädorf e1b1d24572
fix: fix shutdown timer
The shutdown timer was being activated every minute, but then had a 15
minute delay before shutting down. This just caused the delay to keep
resetting and the system to never shut down. This commit decreases the
shutdown delay to 10 minutes, and changes the timer to hit every 15
minutes.
2023-10-04 12:09:28 +02:00

51 lines
1.2 KiB
Nix

{pkgs, ...}: let
shutdownWaitMinutes = 10;
shutdownScript = pkgs.writeShellScriptBin "shutdown-wait" ''
STATUS_FILES="/media/internal/backups-pub-solar/status"
running=""
for f in $STATUS_FILES; do
declare started
declare finished
started=$(source $f ; echo ''${BACKUP_STARTED})
finished=$(source $f ; echo ''${BACKUP_FINISHED})
if [ -z "''${finished}" ]; then
echo "backup $(dirname $f) still running"
running="yes"
break
fi
done
if [ -n "''${running}" ] && [ "''${running}" = "yes" ]; then
echo "backups are still running"
exit 1
fi
echo "WARNING: System will be shut down within the next 15 minutes" | wall
sleep 10
shutdown -P +${builtins.toString shutdownWaitMinutes}
'';
in {
systemd.services."shutdown-after-backup" = {
enable = true;
serviceConfig = {
ExecStart = "${shutdownScript}/bin/shutdown-wait";
Type = "oneshot";
};
};
systemd.timers."shutdown-after-backup" = {
enable = true;
timerConfig = {
OnCalendar = "*-*-* 03..09:*/15:00 Etc/UTC";
};
wantedBy = ["timers.target"];
partOf = ["shutdown-after-backup.service"];
};
}