From 02c3b679aa77fac00a4066f9a9bdb2435c39bdf1 Mon Sep 17 00:00:00 2001 From: Assil Ksiksi Date: Sun, 5 Nov 2023 22:00:11 -0500 Subject: [PATCH] set default StartLimitIntervalSec of 1 day --- compose.go | 13 +++++++++++-- testdata/TestDocker_WithProject_out.nix | 1 + testdata/TestDocker_out.nix | 1 + testdata/TestPodman_WithProject_out.nix | 1 + testdata/TestPodman_out.nix | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compose.go b/compose.go index f5f990d..5092564 100644 --- a/compose.go +++ b/compose.go @@ -16,6 +16,10 @@ import ( "golang.org/x/exp/maps" ) +var ( + defaultStartLimitIntervalSec = int((24 * time.Hour).Seconds()) +) + // Examples: // nixose.systemd.service.RuntimeMaxSec=100 // nixose.systemd.unit.StartLimitBurst=10 @@ -76,8 +80,10 @@ func parseRestartPolicyAndSystemdLabels(service *types.ServiceConfig) (*NixConta if maxAttempts, err := strconv.ParseInt(maxAttemptsString, 10, 64); err != nil { return nil, fmt.Errorf("failed to parse on-failure attempts: %q: %w", maxAttemptsString, err) } else { - v := int(maxAttempts) - p.StartLimitBurst = &v + burst := int(maxAttempts) + p.StartLimitBurst = &burst + // Retry limit resets once per day. + p.StartLimitIntervalSec = &defaultStartLimitIntervalSec } } else { return nil, fmt.Errorf("unsupported restart: %q", restart) @@ -108,6 +114,9 @@ func parseRestartPolicyAndSystemdLabels(service *types.ServiceConfig) (*NixConta if window := restartPolicy.Window; window != nil { windowSecs := int(time.Duration(*window).Seconds()) p.StartLimitIntervalSec = &windowSecs + } else if p.StartLimitBurst != nil { + // Retry limit resets once per day by default. + p.StartLimitIntervalSec = &defaultStartLimitIntervalSec } } } diff --git a/testdata/TestDocker_WithProject_out.nix b/testdata/TestDocker_WithProject_out.nix index 01bf101..3a39a27 100644 --- a/testdata/TestDocker_WithProject_out.nix +++ b/testdata/TestDocker_WithProject_out.nix @@ -164,6 +164,7 @@ Restart = "on-failure"; }; startLimitBurst = 3; + startLimitIntervalSec = 86400; }; virtualisation.oci-containers.containers."traefik" = { image = "docker.io/library/traefik"; diff --git a/testdata/TestDocker_out.nix b/testdata/TestDocker_out.nix index 8130d54..f7930ea 100644 --- a/testdata/TestDocker_out.nix +++ b/testdata/TestDocker_out.nix @@ -164,6 +164,7 @@ Restart = "on-failure"; }; startLimitBurst = 3; + startLimitIntervalSec = 86400; }; virtualisation.oci-containers.containers."traefik" = { image = "docker.io/library/traefik"; diff --git a/testdata/TestPodman_WithProject_out.nix b/testdata/TestPodman_WithProject_out.nix index 1bf871d..044387c 100644 --- a/testdata/TestPodman_WithProject_out.nix +++ b/testdata/TestPodman_WithProject_out.nix @@ -169,6 +169,7 @@ Restart = "on-failure"; }; startLimitBurst = 3; + startLimitIntervalSec = 86400; }; virtualisation.oci-containers.containers."traefik" = { image = "docker.io/library/traefik"; diff --git a/testdata/TestPodman_out.nix b/testdata/TestPodman_out.nix index e2e6b17..f44ae5c 100644 --- a/testdata/TestPodman_out.nix +++ b/testdata/TestPodman_out.nix @@ -169,6 +169,7 @@ Restart = "on-failure"; }; startLimitBurst = 3; + startLimitIntervalSec = 86400; }; virtualisation.oci-containers.containers."traefik" = { image = "docker.io/library/traefik";