Skip to content

Commit

Permalink
container: pass KillSignal and StopTimeout to the systemd scope
Browse files Browse the repository at this point in the history
so that they are honored when systemd terminates the scope.

Closes: https://issues.redhat.com/browse/RHEL-16375

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jun 21, 2024
1 parent e48f313 commit 7d22f04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
g.SetRootPath(c.state.Mountpoint)
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 7d22f04

Please sign in to comment.