Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the RestartSec to service for the generate cmd #16469

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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