aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-04-02 12:23:19 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-03 14:57:16 +0000
commit98b19aeb0ceba4cae10cb89a99ff2af0738027ba (patch)
treeba6a47be4dd1af9a8fc135368c656a82131e49d4 /libpod/container_api.go
parent4d4646d09b6fb1a8914f6a564baf7fbe4d683f9b (diff)
downloadpodman-98b19aeb0ceba4cae10cb89a99ff2af0738027ba.tar.gz
podman-98b19aeb0ceba4cae10cb89a99ff2af0738027ba.tar.bz2
podman-98b19aeb0ceba4cae10cb89a99ff2af0738027ba.zip
Refactor dependency checks from init() into public API
Instead of checking during init(), which could result in major locking issues when used with pods, make our dependency checks in the public API instead. This avoids doing them when we start pods (where, because of the dependency graph, we can reasonably say all dependencies are up before we start a container). Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #577 Approved by: rhatdan
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 639696268..41e754587 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"strconv"
+ "strings"
"time"
"github.com/docker/docker/daemon/caps"
@@ -33,6 +34,15 @@ func (c *Container) Init() (err error) {
return errors.Wrapf(ErrCtrExists, "container %s has already been created in runtime", c.ID())
}
+ notRunning, err := c.checkDependenciesRunning()
+ if err != nil {
+ return errors.Wrapf(err, "error checking dependencies for container %s")
+ }
+ if len(notRunning) > 0 {
+ depString := strings.Join(notRunning, ",")
+ return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
+ }
+
if err := c.prepare(); err != nil {
return err
}
@@ -70,6 +80,15 @@ func (c *Container) Start() (err error) {
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
}
+ notRunning, err := c.checkDependenciesRunning()
+ if err != nil {
+ return errors.Wrapf(err, "error checking dependencies for container %s")
+ }
+ if len(notRunning) > 0 {
+ depString := strings.Join(notRunning, ",")
+ return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
+ }
+
if err := c.prepare(); err != nil {
return err
}
@@ -124,6 +143,15 @@ func (c *Container) StartAndAttach(noStdin bool, keys string) (attachResChan <-c
return nil, errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
}
+ notRunning, err := c.checkDependenciesRunning()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error checking dependencies for container %s")
+ }
+ if len(notRunning) > 0 {
+ depString := strings.Join(notRunning, ",")
+ return nil, errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
+ }
+
if err := c.prepare(); err != nil {
return nil, err
}