summaryrefslogtreecommitdiff
path: root/libpod/container_internal.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_internal.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_internal.go')
-rw-r--r--libpod/container_internal.go59
1 files changed, 55 insertions, 4 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 85c4283b3..6b375ef6f 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -255,6 +255,38 @@ func (c *Container) refresh() error {
return errors.Wrapf(err, "error refreshing state for container %s", c.ID())
}
+ // Remove ctl and attach files, which may persist across reboot
+ if err := c.removeConmonFiles(); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// Remove conmon attach socket and terminal resize FIFO
+// This is necessary for restarting containers
+func (c *Container) removeConmonFiles() error {
+ // Files are allowed to not exist, so ignore ENOENT
+ attachFile := filepath.Join(c.bundlePath(), "attach")
+ if err := os.Remove(attachFile); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s attach file", c.ID())
+ }
+
+ ctlFile := filepath.Join(c.bundlePath(), "ctl")
+ if err := os.Remove(ctlFile); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s ctl file", c.ID())
+ }
+
+ oomFile := filepath.Join(c.bundlePath(), "oom")
+ if err := os.Remove(oomFile); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s OOM file", c.ID())
+ }
+
+ exitFile := filepath.Join(c.runtime.ociRuntime.exitsDir, c.ID())
+ if err := os.Remove(exitFile); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s exit file", c.ID())
+ }
+
return nil
}
@@ -360,10 +392,6 @@ func (c *Container) initAndStart() (err error) {
if c.state.State == ContainerStatePaused {
return errors.Wrapf(ErrCtrStateInvalid, "cannot start paused container %s", c.ID())
}
- // TODO remove this once we can restart containers
- if c.state.State == ContainerStateStopped {
- return errors.Wrapf(ErrNotImplemented, "restarting containers is not yet implemented")
- }
// Mount if necessary
if err := c.mountStorage(); err != nil {
@@ -391,6 +419,29 @@ func (c *Container) initAndStart() (err error) {
}
}()
+ // If we are ContainerStateStopped we need to remove from runtime
+ // And reset to ContainerStateConfigured
+ 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
+ }
+ }
+
// If we are ContainerStateConfigured we need to init()
if c.state.State == ContainerStateConfigured {
if err := c.init(); err != nil {