summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-31 21:13:03 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-03 14:57:16 +0000
commit4d4646d09b6fb1a8914f6a564baf7fbe4d683f9b (patch)
tree5ab646cb26f5334802701052de6a90317fb86b2c
parent489d977b22a01c310c3484a24238b7ae158c0d8e (diff)
downloadpodman-4d4646d09b6fb1a8914f6a564baf7fbe4d683f9b.tar.gz
podman-4d4646d09b6fb1a8914f6a564baf7fbe4d683f9b.tar.bz2
podman-4d4646d09b6fb1a8914f6a564baf7fbe4d683f9b.zip
Do not require Init() before Start()
This will help dependency races Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #577 Approved by: rhatdan
-rw-r--r--libpod/container_api.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 6b30141a5..639696268 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -48,7 +48,9 @@ func (c *Container) Init() (err error) {
}
// Start starts a container
-// Start can start created or stopped containers
+// Start can start configured, created or stopped containers
+// For configured containers, the container will be initialized first, then
+// started
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
// Init()
func (c *Container) Start() (err error) {
@@ -62,7 +64,9 @@ func (c *Container) Start() (err error) {
}
// Container must be created or stopped to be started
- if !(c.state.State == ContainerStateCreated || c.state.State == ContainerStateStopped) {
+ if !(c.state.State == ContainerStateConfigured ||
+ c.state.State == ContainerStateCreated ||
+ c.state.State == ContainerStateStopped) {
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
}
@@ -77,11 +81,16 @@ func (c *Container) Start() (err error) {
}
}()
- // Reinitialize the container if we need to
if c.state.State == ContainerStateStopped {
+ // Reinitialize the container if we need to
if err := c.reinit(); err != nil {
return err
}
+ } else if c.state.State == ContainerStateConfigured {
+ // Or initialize it for the first time if necessary
+ if err := c.init(); err != nil {
+ return err
+ }
}
// Start the container
@@ -89,7 +98,9 @@ func (c *Container) Start() (err error) {
}
// StartAndAttach starts a container and attaches to it
-// StartAndAttach can start created or stopped containers
+// StartAndAttach can start configured, created or stopped containers
+// For configured containers, the container will be initialized first, then
+// started
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
// Init()
// If successful, an error channel will be returned containing the result of the
@@ -107,7 +118,9 @@ func (c *Container) StartAndAttach(noStdin bool, keys string) (attachResChan <-c
}
// Container must be created or stopped to be started
- if !(c.state.State == ContainerStateCreated || c.state.State == ContainerStateStopped) {
+ if !(c.state.State == ContainerStateConfigured ||
+ c.state.State == ContainerStateCreated ||
+ c.state.State == ContainerStateStopped) {
return nil, errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
}
@@ -122,11 +135,16 @@ func (c *Container) StartAndAttach(noStdin bool, keys string) (attachResChan <-c
}
}()
- // Reinitialize the container if we need to
if c.state.State == ContainerStateStopped {
+ // Reinitialize the container if we need to
if err := c.reinit(); err != nil {
return nil, err
}
+ } else if c.state.State == ContainerStateConfigured {
+ // Or initialize it for the first time if necessary
+ if err := c.init(); err != nil {
+ return nil, err
+ }
}
attachChan := make(chan error)