From 1c0a3473cf144980de3c3c5415b220fe788c35cf Mon Sep 17 00:00:00 2001 From: aadi58002 Date: Thu, 10 Nov 2022 10:51:21 +0530 Subject: [PATCH] Add the RestartSec to service for the generate cmd Signed-off-by: aadi58002 Signed-off-by: aadi58002 --- pkg/systemd/generate/containers.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index deb8ade924..ccf9232ea6 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -28,6 +28,7 @@ type containerInfo struct { NotifyAccess string StopTimeout uint RestartPolicy string + RestartSec uint StartLimitBurst string PIDFile string ContainerIDFile string @@ -87,6 +88,9 @@ Environment={{{{- range $index, $value := .ExtraEnvs -}}}}{{{{if $index}}}} {{{{ Environment={{{{ $value }}}}{{{{end}}}} {{{{- end}}}} Restart={{{{.RestartPolicy}}}} +{{{{- if .RestartSec}}}} +RestartSec={{{{.RestartSec}}}} +{{{{- end}}}} {{{{- if .StartLimitBurst}}}} StartLimitBurst={{{{.StartLimitBurst}}}} {{{{- end}}}} @@ -156,6 +160,10 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste logrus.Warnf("Container %s has restart policy %q which can lead to issues on shutdown: consider recreating the container without a restart policy and use systemd's restart mechanism instead", ctr.ID(), config.RestartPolicy) } } + RestartSec := uint(0) + if options.RestartSec != nil { + RestartSec = *options.RestartSec + } createCommand := []string{} if config.CreateCommand != nil { @@ -182,6 +190,7 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste ServiceName: serviceName, ContainerNameOrID: nameOrID, RestartPolicy: define.DefaultRestartPolicy, + RestartSec: RestartSec, PIDFile: conmonPidFile, TimeoutStartSec: startTimeout, StopTimeout: stopTimeout, @@ -448,6 +457,10 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst } } + if options.RestartSec != nil { + info.RestartSec = *options.RestartSec + } + envs, err := fs.GetStringArray("env") if err != nil { return "", err