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 03fb8a3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ 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)
// Retry limit resets once per day.
interval := int((time.Hour * 24).Seconds())
p.StartLimitBurst = &burst
p.StartLimitIntervalSec = &interval
}
} else {
return nil, fmt.Errorf("unsupported restart: %q", restart)
Expand Down Expand Up @@ -108,6 +111,10 @@ 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.
windowSecs := int((time.Hour * 24).Seconds())
p.StartLimitIntervalSec = &windowSecs
}
}
}
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 03fb8a3

Please sign in to comment.