Skip to content

Commit

Permalink
Add the RestartSec to service for the generate cmd
Browse files Browse the repository at this point in the history
Signed-off-by: aadi58002 <aadi58002gmail.com>

Signed-off-by: aadi58002 <aadi58002gmail.com>
  • Loading branch information
aadi58002 committed Nov 10, 2022
1 parent fbdf0c9 commit 1c0a347
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/systemd/generate/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type containerInfo struct {
NotifyAccess string
StopTimeout uint
RestartPolicy string
RestartSec uint
StartLimitBurst string
PIDFile string
ContainerIDFile string
Expand Down Expand Up @@ -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}}}}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c0a347

Please sign in to comment.