summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2018-01-29 11:59:33 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-30 05:02:12 +0000
commitc60d8a0671b48ffdeda68895e0b7d97b252d66d9 (patch)
tree6be6b971913ae7763b79d7eef68dc71284a841c5 /libpod/container_api.go
parentdd133a1ad25f75e5ddd53ed6cf59eedfb6838f54 (diff)
downloadpodman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.tar.gz
podman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.tar.bz2
podman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.zip
Add StopWithTimeout API function for containers
Normal Stop should not need a timeout, and should use the default Add a function that does accept a timeout aside it Signed-off-by: Matthew Heon <mheon@redhat.com> Closes: #272 Approved by: rhatdan
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go36
1 files changed, 18 insertions, 18 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 2b3c83eb2..cd3485880 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -326,10 +326,11 @@ func (c *Container) Start() error {
}
// Stop uses the container's stop signal (or SIGTERM if no signal was specified)
-// to stop the container, and if it has not stopped after the given timeout (in
-// seconds), uses SIGKILL to attempt to forcibly stop the container.
-// If timeout is 0, SIGKILL will be used immediately
-func (c *Container) Stop(timeout uint) error {
+// to stop the container, and if it has not stopped after container's stop
+// timeout, SIGKILL is used to attempt to forcibly stop the container
+// Default stop timeout is 10 seconds, but can be overridden when the container
+// is created
+func (c *Container) Stop() error {
if !c.locked {
c.lock.Lock()
defer c.lock.Unlock()
@@ -339,24 +340,23 @@ func (c *Container) Stop(timeout uint) error {
}
}
- logrus.Debugf("Stopping ctr %s with timeout %d", c.ID(), timeout)
-
- if c.state.State == ContainerStateConfigured ||
- c.state.State == ContainerStateUnknown ||
- c.state.State == ContainerStatePaused {
- return errors.Wrapf(ErrCtrStateInvalid, "can only stop created, running, or stopped containers")
- }
+ return c.stop(c.config.StopTimeout)
+}
- if err := c.runtime.ociRuntime.stopContainer(c, timeout); err != nil {
- return err
- }
+// StopWithTimeout is a version of Stop that allows a timeout to be specified
+// manually. If timeout is 0, SIGKILL will be used immediately to kill the
+// container.
+func (c *Container) StopWithTimeout(timeout uint) error {
+ if !c.locked {
+ c.lock.Lock()
+ defer c.lock.Unlock()
- // Sync the container's state to pick up return code
- if err := c.runtime.ociRuntime.updateContainerStatus(c); err != nil {
- return err
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
}
- return c.cleanupStorage()
+ return c.stop(timeout)
}
// Kill sends a signal to a container