Skip to content

Commit

Permalink
set default StartLimitIntervalSec of 1 day
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 6, 2023
1 parent d72b0ae commit 02c3b67
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down
1 change: 1 addition & 0 deletions testdata/TestDocker_WithProject_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
Restart = "on-failure";
};
startLimitBurst = 3;
startLimitIntervalSec = 86400;
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down
1 change: 1 addition & 0 deletions testdata/TestDocker_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
Restart = "on-failure";
};
startLimitBurst = 3;
startLimitIntervalSec = 86400;
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down
1 change: 1 addition & 0 deletions testdata/TestPodman_WithProject_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
Restart = "on-failure";
};
startLimitBurst = 3;
startLimitIntervalSec = 86400;
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down
1 change: 1 addition & 0 deletions testdata/TestPodman_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
Restart = "on-failure";
};
startLimitBurst = 3;
startLimitIntervalSec = 86400;
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down

0 comments on commit 02c3b67

Please sign in to comment.