git.delta.rocks / jrsonnet / refs/commits / e9e8e99657ad

difftreelog

feat more resilent rollback service

Yaroslav Bolyukin2023-10-22parent: #741106e.patch.diff
in: trunk

1 file changed

modifiednixos/rollback.nixdiffbeforeafterboth
66
7 systemd.services.rollback-watchdog = {7 systemd.services.rollback-watchdog = {
8 description = "Rollback watchdog";8 description = "Rollback watchdog";
9 script = ''9 script = ''
10 set -eu10 set -eux
11 if [ -f /etc/fleet_rollback_marker ]; then11 if [ -f /etc/fleet_rollback_marker ]; then
12 echo "found the rollback marker, switching to older generation"12 echo "found the rollback marker, switching to older generation"
13 target=$(cat /etc/fleet_rollback_marker)13 target=$(cat /etc/fleet_rollback_marker)
14 echo "rolling back profile"14 echo "rolling back profile"
15 nix profile rollback --profile /nix/var/nix/profiles/system --to "$target"15 nix profile rollback --profile /nix/var/nix/profiles/system --to "$target"
16 echo "executing activation script"16 echo "executing activation script"
17 "/nix/var/nix/profiles/system-$target-link/bin/switch-to-configuration" switch17 "/nix/var/nix/profiles/system-$target-link/bin/switch-to-configuration" switch || true
18 echo "removing rollback marker"18 echo "removing rollback marker"
19 rm -f /etc/fleet_rollback_marker19 rm -f /etc/fleet_rollback_marker
20 else20 else
21 echo "rollback marker was removed, upgrade is succeeded"21 echo "rollback marker was removed, upgrade is succeeded"
22 fi22 fi
23 '';23 '';
24 path = [24 path = [
25 # Should have nix-command support25 # Should have nix-command support
26 config.nix.package26 config.nix.package
27 ];27 ];
28 serviceConfig.Type = "exec";28 serviceConfig.Type = "exec";
29 unitConfig = {29 unitConfig = {
30 X-StopOnRemoval = false;30 X-StopOnRemoval = false;
31 X-RestartIfChanged = false;
32 X-StopIfChanged = false;
31 };33 };
32 };34 };
3335
34 systemd.timers.rollback-watchdog = {36 systemd.timers.rollback-watchdog = {
35 description = "Timer for rollback watchdog";37 description = "Timer for rollback watchdog";
36 wantedBy = ["timers.target"];38 wantedBy = ["timers.target"];
37 timerConfig = {39 timerConfig = {
38 OnUnitActiveSec = "3min";40 OnActiveSec = "3min";
39 RemainAfterElapse = false;41 RemainAfterElapse = false;
40 };42 };
41 unitConfig = {43 unitConfig = {