Skip to content

Commit

Permalink
Merge pull request #23064 from giuseppe/podman-pass-timeout-stop-to-s…
Browse files Browse the repository at this point in the history
…ystemd

container: pass StopTimeout to the systemd slice
  • Loading branch information
openshift-merge-bot[bot] authored Jun 23, 2024
2 parents 25bc426 + 7d22f04 commit bf2de41
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libpod/container_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ type ContainerMiscConfig struct {
Labels map[string]string `json:"labels,omitempty"`
// StopSignal is the signal that will be used to stop the container
StopSignal uint `json:"stopSignal,omitempty"`
// StopTimeout is the signal that will be used to stop the container
// StopTimeout is maximum time a container is allowed to run after getting the stop signal
StopTimeout uint `json:"stopTimeout,omitempty"`
// Timeout is maximum time a container will run before getting the kill signal
Timeout uint `json:"timeout,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,15 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
g.SetRootPath(rootPath)
g.AddAnnotation("org.opencontainers.image.stopSignal", strconv.FormatUint(uint64(c.config.StopSignal), 10))

if c.config.StopSignal != 0 {
g.AddAnnotation("org.systemd.property.KillSignal", strconv.FormatUint(uint64(c.config.StopSignal), 10))
}

if c.config.StopTimeout != 0 {
annotation := fmt.Sprintf("uint64 %d", c.config.StopTimeout*1000000) // sec to usec
g.AddAnnotation("org.systemd.property.TimeoutStopUSec", annotation)
}

if _, exists := g.Config.Annotations[annotations.ContainerManager]; !exists {
g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
}
Expand Down
17 changes: 17 additions & 0 deletions test/system/250-systemd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,21 @@ $name stderr" "logs work with passthrough"
is "$output" ".*\[DEPRECATED\] Generate systemd units"
run_podman rm test
}

@test "podman passes down the KillSignal and StopTimeout setting" {
ctr=systemd_test_$(random_string 5)

run_podman run -d --name $ctr --stop-signal 5 --stop-timeout 7 --rm $IMAGE top
run_podman inspect $ctr --format '{{ .Id }}'
id="$output"

run systemctl show -p TimeoutStopUSec "libpod-${id}.scope"
assert "$output" == "TimeoutStopUSec=7s"

run systemctl show -p KillSignal "libpod-${id}.scope"
assert "$output" == "KillSignal=5"

# Clean up
run_podman rm -t 0 -f $ctr
}
# vim: filetype=sh

0 comments on commit bf2de41

Please sign in to comment.