summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-05-03 17:12:00 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-04 10:57:50 +0000
commitc34e4541774e2b7ff08017e123c0ef0836a66be4 (patch)
tree6882d87970f5205c8d8eb7abc205cb6731c0be39 /libpod/container_api.go
parent5ae940a57427ffe0588d83d3c2a4a1deb7a37208 (diff)
downloadpodman-c34e4541774e2b7ff08017e123c0ef0836a66be4.tar.gz
podman-c34e4541774e2b7ff08017e123c0ef0836a66be4.tar.bz2
podman-c34e4541774e2b7ff08017e123c0ef0836a66be4.zip
Optionally init() during container restart
This allows us to restart containers that have never been started without error. This makes RestartWithTimeout work with running, stopped, and created containers. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #719 Approved by: rhatdan
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index f0742d9f1..0ddccfe8e 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -726,7 +726,7 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
}
if c.state.State == ContainerStateUnknown || c.state.State == ContainerStatePaused {
- return errors.Errorf("unable to restart a container in a paused or unknown state")
+ return errors.Wrapf(ErrCtrStateInvalid, "unable to restart a container in a paused or unknown state")
}
if c.state.State == ContainerStateRunning {
@@ -737,7 +737,6 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
if err := c.prepare(); err != nil {
return err
}
-
defer func() {
if err != nil {
if err2 := c.cleanup(); err2 != nil {
@@ -751,6 +750,12 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
if err := c.reinit(ctx); err != nil {
return err
}
+ } else if c.state.State == ContainerStateConfigured {
+ // Initialize the container if it has never been initialized
+ if err := c.init(ctx); err != nil {
+ return err
+ }
}
+
return c.start()
}