From 1f49f555af0709ea7c12becdb750ba60a00eaf1d Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 19 Dec 2017 15:42:30 -0500 Subject: Plumb through the --stop-timeout signal handling podman run/create have the ability to set the stop timeout flag. We need to stop it in the database. Also Allowing negative time for stop timeout makes no sense, so switching to timeout of uint, allows user to specify huge timeout values. Signed-off-by: Daniel J Walsh Closes: #158 Approved by: TomSweeneyRedHat --- cmd/podman/common.go | 1 + cmd/podman/create.go | 4 ++-- cmd/podman/spec.go | 2 +- cmd/podman/stop.go | 17 +++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/common.go b/cmd/podman/common.go index 57e2ff717..e6c2645c9 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -393,6 +393,7 @@ var createFlags = []cli.Flag{ cli.IntFlag{ Name: "stop-timeout", Usage: "Timeout (in seconds) to stop a container. Default is 10", + Value: libpod.CtrRemoveTimeout, }, cli.StringSliceFlag{ Name: "storage-opt", diff --git a/cmd/podman/create.go b/cmd/podman/create.go index d3e14742b..8b64a1cb0 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -110,7 +110,7 @@ type createConfig struct { ShmDir string SigProxy bool //sig-proxy StopSignal syscall.Signal // stop-signal - StopTimeout int64 // stop-timeout + StopTimeout uint // stop-timeout StorageOpts []string //storage-opt Sysctl map[string]string //sysctl Tmpfs []string // tmpfs @@ -494,7 +494,7 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er ShmDir: shmDir, SigProxy: c.Bool("sig-proxy"), StopSignal: stopSignal, - StopTimeout: c.Int64("stop-timeout"), + StopTimeout: c.Uint("stop-timeout"), StorageOpts: c.StringSlice("storage-opt"), Sysctl: sysctl, Tmpfs: c.StringSlice("tmpfs"), diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go index dc6e24c24..037b18950 100644 --- a/cmd/podman/spec.go +++ b/cmd/podman/spec.go @@ -559,7 +559,7 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er // TODO should not happen if --net=host options = append(options, libpod.WithNetNS([]ocicni.PortMapping{})) options = append(options, libpod.WithStopSignal(c.StopSignal)) - + options = append(options, libpod.WithStopTimeout(c.StopTimeout)) return options, nil } diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go index 3b1ffbba5..f85512d47 100644 --- a/cmd/podman/stop.go +++ b/cmd/podman/stop.go @@ -6,17 +6,15 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) var ( - defaultTimeout int64 = 10 - stopFlags = []cli.Flag{ - cli.Int64Flag{ + stopFlags = []cli.Flag{ + cli.UintFlag{ Name: "timeout, t", Usage: "Seconds to wait for stop before killing the container", - Value: defaultTimeout, + Value: libpod.CtrRemoveTimeout, }, cli.BoolFlag{ Name: "all, a", @@ -43,7 +41,6 @@ var ( func stopCmd(c *cli.Context) error { args := c.Args() - stopTimeout := c.Int64("timeout") if c.Bool("all") && len(args) > 0 { return errors.Errorf("no arguments are needed with -a") } @@ -60,8 +57,6 @@ func stopCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - logrus.Debugf("Stopping containers with timeout %d", stopTimeout) - var filterFuncs []libpod.ContainerFilter var containers []*libpod.Container var lastError error @@ -91,6 +86,12 @@ func stopCmd(c *cli.Context) error { } for _, ctr := range containers { + var stopTimeout uint + if c.IsSet("timeout") { + stopTimeout = c.Uint("timeout") + } else { + stopTimeout = ctr.StopTimeout() + } if err := ctr.Stop(stopTimeout); err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) -- cgit v1.2.3-54-g00ecf