summaryrefslogtreecommitdiff
path: root/libpod/runtime_ctr.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-23 14:06:43 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-29 12:15:15 +0000
commit831e2c30d479a92c203d2caf82106cb85a6cdfc8 (patch)
tree9c3970ed34441fee8990265685fbdf7654c1af51 /libpod/runtime_ctr.go
parenta1d0d9f5d1d72f3ca0d1d2af36f9542f6f21ff91 (diff)
downloadpodman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.tar.gz
podman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.tar.bz2
podman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.zip
Add ability to kill and stop containers
Also migrates kpod kill and kpod stop to libpod to use the new code Fixes force removing containers, and actually deletes containers in runc when removing them Start is now capable of starting even when the container is unmounted Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #68 Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r--libpod/runtime_ctr.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index fd92a3411..9a91e0a48 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -7,6 +7,8 @@ import (
"github.com/sirupsen/logrus"
)
+const ctrRemoveTimeout = 10
+
// Contains the public Runtime API for containers
// A CtrCreateOption is a functional option which alters the Container created
@@ -97,7 +99,11 @@ func (r *Runtime) RemoveContainer(c *Container, force bool) error {
}
// Check that the container's in a good state to be removed
- if !(c.state.State == ContainerStateConfigured ||
+ if c.state.State == ContainerStateRunning && force {
+ if err := r.ociRuntime.stopContainer(c, ctrRemoveTimeout); err != nil {
+ return errors.Wrapf(err, "cannot remove container %s as it could not be stopped", c.ID())
+ }
+ } else if !(c.state.State == ContainerStateConfigured ||
c.state.State == ContainerStateCreated ||
c.state.State == ContainerStateStopped) {
return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is running or paused", c.ID())
@@ -112,6 +118,11 @@ func (r *Runtime) RemoveContainer(c *Container, force bool) error {
return errors.Wrapf(err, "error removing container from state")
}
+ // Delete the container
+ if err := r.ociRuntime.deleteContainer(c); err != nil {
+ return errors.Wrapf(err, "error removing container %s from runc", c.ID())
+ }
+
// Set container as invalid so it can no longer be used
c.valid = false