mirror of
https://github.com/containers/podman.git
synced 2025-07-03 17:27:18 +08:00
podman: fix --sdnotify=healthy with --rm
Now WaitForExit returns the exit code as stored in the db instead of returning an error when the container was removed. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -581,11 +581,16 @@ func (c *Container) Wait(ctx context.Context) (int32, error) {
|
|||||||
// WaitForExit blocks until the container exits and returns its exit code. The
|
// WaitForExit blocks until the container exits and returns its exit code. The
|
||||||
// argument is the interval at which checks the container's status.
|
// argument is the interval at which checks the container's status.
|
||||||
func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration) (int32, error) {
|
func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration) (int32, error) {
|
||||||
|
id := c.ID()
|
||||||
if !c.valid {
|
if !c.valid {
|
||||||
|
// if the container is not valid at this point as it was deleted,
|
||||||
|
// check if the exit code was recorded in the db.
|
||||||
|
exitCode, err := c.runtime.state.GetContainerExitCode(id)
|
||||||
|
if err == nil {
|
||||||
|
return exitCode, nil
|
||||||
|
}
|
||||||
return -1, define.ErrCtrRemoved
|
return -1, define.ErrCtrRemoved
|
||||||
}
|
}
|
||||||
|
|
||||||
id := c.ID()
|
|
||||||
var conmonTimer time.Timer
|
var conmonTimer time.Timer
|
||||||
conmonTimerSet := false
|
conmonTimerSet := false
|
||||||
|
|
||||||
|
@ -242,6 +242,14 @@ READY=1" "Container log after healthcheck run"
|
|||||||
is "$output" "finished" "make sure container exited successfully"
|
is "$output" "finished" "make sure container exited successfully"
|
||||||
run_podman rm -f -t0 $ctr
|
run_podman rm -f -t0 $ctr
|
||||||
|
|
||||||
|
ctr=$(random_string)
|
||||||
|
run_podman 12 run --name $ctr --rm \
|
||||||
|
--health-cmd="touch /terminate" \
|
||||||
|
--sdnotify=healthy \
|
||||||
|
$IMAGE sh -c 'while test \! -e /terminate; do sleep 0.1; done; echo finished; exit 12'
|
||||||
|
is "$output" "finished" "make sure container exited"
|
||||||
|
run_podman rm -f -t0 $ctr
|
||||||
|
|
||||||
_stop_socat
|
_stop_socat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user