From 566b78dd02e91f376e9f219cb96ddba153671eb5 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 22 Nov 2021 11:05:59 +0100 Subject: generate systemd: add --start-timeout flag Add a new flag to set the start timeout for a generated systemd unit. To make naming consistent, add a new --stop-timeout flag as well and let the previous --time map to it. Fixes: #11618 Signed-off-by: Valentin Rothberg --- pkg/systemd/generate/containers.go | 17 ++++++++++++++--- pkg/systemd/generate/pods.go | 6 +++--- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'pkg/systemd') diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index 95ff13371..2fdec5fb1 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -73,6 +73,8 @@ type containerInfo struct { ExecStartPre string // ExecStart of the unit. ExecStart string + // TimeoutStartSec of the unit. + TimeoutStartSec uint // TimeoutStopSec of the unit. TimeoutStopSec uint // ExecStop of the unit. @@ -109,6 +111,9 @@ Restart={{{{.RestartPolicy}}}} {{{{- if .StartLimitBurst}}}} StartLimitBurst={{{{.StartLimitBurst}}}} {{{{- end}}}} +{{{{- if ne .TimeoutStartSec 0}}}} +TimeoutStartSec={{{{.TimeoutStartSec}}}} +{{{{- end}}}} TimeoutStopSec={{{{.TimeoutStopSec}}}} {{{{- if .ExecStartPre}}}} ExecStartPre={{{{.ExecStartPre}}}} @@ -148,9 +153,14 @@ func ContainerUnit(ctr *libpod.Container, options entities.GenerateSystemdOption } func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSystemdOptions) (*containerInfo, error) { - timeout := ctr.StopTimeout() + stopTimeout := ctr.StopTimeout() if options.StopTimeout != nil { - timeout = *options.StopTimeout + stopTimeout = *options.StopTimeout + } + + startTimeout := uint(0) + if options.StartTimeout != nil { + startTimeout = *options.StartTimeout } config := ctr.Config() @@ -185,7 +195,8 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste ContainerNameOrID: nameOrID, RestartPolicy: define.DefaultRestartPolicy, PIDFile: conmonPidFile, - StopTimeout: timeout, + TimeoutStartSec: startTimeout, + StopTimeout: stopTimeout, GenerateTimestamp: true, CreateCommand: createCommand, RunRoot: runRoot, diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go index 38f7e8e3e..f4cc31c8e 100644 --- a/pkg/systemd/generate/pods.go +++ b/pkg/systemd/generate/pods.go @@ -195,9 +195,9 @@ func generatePodInfo(pod *libpod.Pod, options entities.GenerateSystemdOptions) ( return nil, errors.Wrap(err, "could not find infra container") } - timeout := infraCtr.StopTimeout() + stopTimeout := infraCtr.StopTimeout() if options.StopTimeout != nil { - timeout = *options.StopTimeout + stopTimeout = *options.StopTimeout } config := infraCtr.Config() @@ -223,7 +223,7 @@ func generatePodInfo(pod *libpod.Pod, options entities.GenerateSystemdOptions) ( ServiceName: serviceName, InfraNameOrID: ctrNameOrID, PIDFile: conmonPidFile, - StopTimeout: timeout, + StopTimeout: stopTimeout, GenerateTimestamp: true, CreateCommand: createCommand, } -- cgit v1.2.3-54-g00ecf