summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-13 11:49:24 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-15 17:45:11 +0000
commit02a26c2934eea13799ae950827df54ec995312bc (patch)
tree6b98d4cb0ef0668c03b6ec2b78b45b771c7a81d7 /libpod/container_api.go
parentff091cf731cb28e5d38ff843781115d352ea1530 (diff)
downloadpodman-02a26c2934eea13799ae950827df54ec995312bc.tar.gz
podman-02a26c2934eea13799ae950827df54ec995312bc.tar.bz2
podman-02a26c2934eea13799ae950827df54ec995312bc.zip
Implement container restarting
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #482 Approved by: baude
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 7e2197614..499cf826f 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -63,6 +63,9 @@ func (c *Container) Init() (err error) {
}
// Start starts a container
+// Start can start created or stopped containers
+// Stopped containers will be deleted and re-created in runc, undergoing a fresh
+// Init()
func (c *Container) Start() (err error) {
if !c.locked {
c.lock.Lock()
@@ -78,11 +81,6 @@ func (c *Container) Start() (err error) {
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
}
- // TODO remove this when we patch conmon to support restarting containers
- if c.state.State == ContainerStateStopped {
- return errors.Wrapf(ErrNotImplemented, "restarting a stopped container is not yet supported")
- }
-
// Mount storage for the container if necessary
if err := c.mountStorage(); err != nil {
return err
@@ -109,6 +107,34 @@ func (c *Container) Start() (err error) {
}
}()
+ // Reinitialize the container if we need to
+ if c.state.State == ContainerStateStopped {
+ // If necessary, delete attach and ctl files
+ if err := c.removeConmonFiles(); err != nil {
+ return err
+ }
+
+ // Delete the container in the runtime
+ if err := c.runtime.ociRuntime.deleteContainer(c); err != nil {
+ return errors.Wrapf(err, "error removing container %s from runtime", c.ID())
+ }
+
+ // Our state is now Configured, as we've removed ourself from
+ // the runtime
+ // Set and save now to make sure that, if the init() below fails
+ // we still have a valid state
+ c.state.State = ContainerStateConfigured
+ if err := c.save(); err != nil {
+ return err
+ }
+
+ // Reinitialize the container
+ if err := c.init(); err != nil {
+ return err
+ }
+ }
+
+ // Start the container
return c.start()
}