summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-04-27 14:00:32 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-03 17:31:33 +0000
commit8dfebd4607c1152bd26c4a586e6d56a196c56e54 (patch)
treee4fdfcc0b1813fccd2ee6134931afbf2725a8208 /libpod/container_api.go
parentfae5033a01b78d3e8f23c1c9438bc5534dfe0fa3 (diff)
downloadpodman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.tar.gz
podman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.tar.bz2
podman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.zip
varlink containers
first pass at adding in the container related endpoints/methods for the libpod backend. Couple of important notes: * endpoints that can use a console are not going to be done until we have "remote" console * several of the container methods should probably be able to stream as opposed to a one-off return Signed-off-by: baude <bbaude@redhat.com> Closes: #708 Approved by: baude
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index aa1e7966f..f0742d9f1 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -705,3 +705,52 @@ func (c *Container) Sync() error {
return nil
}
+
+// RestartWithTimeout restarts a running container and takes a given timeout in uint
+func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error {
+ if !c.batched {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
+ }
+
+ 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 c.state.State == ContainerStateUnknown || c.state.State == ContainerStatePaused {
+ return errors.Errorf("unable to restart a container in a paused or unknown state")
+ }
+
+ if c.state.State == ContainerStateRunning {
+ if err := c.stop(timeout); err != nil {
+ return err
+ }
+ }
+ if err := c.prepare(); err != nil {
+ return err
+ }
+
+ defer func() {
+ if err != nil {
+ if err2 := c.cleanup(); err2 != nil {
+ logrus.Errorf("error cleaning up container %s: %v", c.ID(), err2)
+ }
+ }
+ }()
+
+ if c.state.State == ContainerStateStopped {
+ // Reinitialize the container if we need to
+ if err := c.reinit(ctx); err != nil {
+ return err
+ }
+ }
+ return c.start()
+}