Merge pull request #1434 from rhatdan/wait

Add --interval flag to podman wait
This commit is contained in:
Matthew Heon 2018-09-14 16:52:13 -04:00 committed by GitHub
commit 0405555345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 10 deletions

View File

@ -286,7 +286,7 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man .ins
fi fi
.install.easyjson: .gopathok .install.easyjson: .gopathok
if [ ! -x "$(GOBIN)/ffjson" ]; then\ if [ ! -x "$(GOBIN)/easyffjson" ]; then\
$(GO) get -u github.com/mailru/easyjson/...; \ $(GO) get -u github.com/mailru/easyjson/...; \
fi fi

View File

@ -223,7 +223,7 @@ func runCmd(c *cli.Context) error {
return err return err
} }
if ecode, err := ctr.Wait(); err != nil { if ecode, err := ctr.Wait(libpod.WaitTimeout); err != nil {
if errors.Cause(err) == libpod.ErrNoSuchCtr { if errors.Cause(err) == libpod.ErrNoSuchCtr {
// The container may have been removed // The container may have been removed
// Go looking for an exit file // Go looking for an exit file

View File

@ -115,7 +115,7 @@ func startCmd(c *cli.Context) error {
return errors.Wrapf(err, "unable to start container %s", ctr.ID()) return errors.Wrapf(err, "unable to start container %s", ctr.ID())
} }
if ecode, err := ctr.Wait(); err != nil { if ecode, err := ctr.Wait(libpod.WaitTimeout); err != nil {
logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err) logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err)
} else { } else {
exitCode = int(ecode) exitCode = int(ecode)

View File

@ -3,8 +3,10 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -15,7 +17,14 @@ var (
Block until one or more containers stop and then print their exit codes Block until one or more containers stop and then print their exit codes
` `
waitFlags = []cli.Flag{LatestFlag} waitFlags = []cli.Flag{
cli.UintFlag{
Name: "interval, i",
Usage: "Milliseconds to wait before polling for completion",
Value: uint(libpod.WaitTimeout),
},
LatestFlag,
}
waitCommand = cli.Command{ waitCommand = cli.Command{
Name: "wait", Name: "wait",
Usage: "Block on one or more containers", Usage: "Block on one or more containers",
@ -57,7 +66,10 @@ func waitCmd(c *cli.Context) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "unable to find container %s", container) return errors.Wrapf(err, "unable to find container %s", container)
} }
returnCode, err := ctr.Wait() if c.Uint("interval") == 0 {
return errors.Errorf("interval must be greater then 0")
}
returnCode, err := ctr.Wait(time.Duration(c.Uint("interval")))
if err != nil { if err != nil {
if lastError != nil { if lastError != nil {
fmt.Fprintln(os.Stderr, lastError) fmt.Fprintln(os.Stderr, lastError)

View File

@ -2012,7 +2012,9 @@ _podman_wait() {
local boolean_options=" local boolean_options="
--help --help
-h -h
-l -i
-l
--interval
--latest" --latest"
case "$cur" in case "$cur" in
-*) -*)

View File

@ -17,6 +17,9 @@ After the container stops, the container's return code is printed.
Print usage statement Print usage statement
**--interval, i**"
Microseconds to wait before polling for completion
**--latest, -l** **--latest, -l**
Instead of providing the container name or ID, use the last created container. If you use methods other than Podman Instead of providing the container name or ID, use the last created container. If you use methods other than Podman

View File

@ -36,6 +36,8 @@ const (
ContainerStateStopped ContainerStatus = iota ContainerStateStopped ContainerStatus = iota
// ContainerStatePaused indicates that the container has been paused // ContainerStatePaused indicates that the container has been paused
ContainerStatePaused ContainerStatus = iota ContainerStatePaused ContainerStatus = iota
// WaitTimeout is the wait timeout before checking for container exit
WaitTimeout = time.Second / time.Millisecond
) )
// CgroupfsDefaultCgroupParent is the cgroup parent for CGroupFS in libpod // CgroupfsDefaultCgroupParent is the cgroup parent for CGroupFS in libpod

View File

@ -592,12 +592,11 @@ func (c *Container) Inspect(size bool) (*inspect.ContainerInspectData, error) {
} }
// Wait blocks on a container to exit and returns its exit code // Wait blocks on a container to exit and returns its exit code
func (c *Container) Wait() (int32, error) { func (c *Container) Wait(waitTimeout time.Duration) (int32, error) {
if !c.valid { if !c.valid {
return -1, ErrCtrRemoved return -1, ErrCtrRemoved
} }
err := wait.PollImmediateInfinite(waitTimeout*time.Millisecond,
err := wait.PollImmediateInfinite(100*time.Millisecond,
func() (bool, error) { func() (bool, error) {
stopped, err := c.isStopped() stopped, err := c.isStopped()
if err != nil { if err != nil {

View File

@ -341,7 +341,7 @@ func (i *LibpodAPI) WaitContainer(call iopodman.VarlinkCall, name string) error
if err != nil { if err != nil {
return call.ReplyContainerNotFound(name) return call.ReplyContainerNotFound(name)
} }
exitCode, err := ctr.Wait() exitCode, err := ctr.Wait(libpod.WaitTimeout)
if err != nil { if err != nil {
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }