diff options
author | haircommander <pehunt@redhat.com> | 2018-07-23 15:56:12 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-07-25 17:54:27 +0000 |
commit | 7789284cbe8f5068d66c90c257b9784505d4a027 (patch) | |
tree | 864b09233236bdb699a98a67006d0bc47de40c94 /libpod/container_internal.go | |
parent | e56717833e52db68a334018a43a0b1a698d30aa8 (diff) | |
download | podman-7789284cbe8f5068d66c90c257b9784505d4a027.tar.gz podman-7789284cbe8f5068d66c90c257b9784505d4a027.tar.bz2 podman-7789284cbe8f5068d66c90c257b9784505d4a027.zip |
Added pod.Restart() functionality to libpod.
Moved contents of RestartWithTimeout to restartWithTimeout in container_internal to be able to call restart without locking in function.
Refactored startNode to be able to either start or restart a node.
Built pod Restart() with new startNode with refresh true.
Signed-off-by: haircommander <pehunt@redhat.com>
Closes: #1152
Approved by: rhatdan
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 55fd7369d..8a96af0ab 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -718,6 +718,43 @@ func (c *Container) unpause() error { return c.save() } +// Internal, non-locking function to restart a container +func (c *Container) restartWithTimeout(ctx context.Context, timeout uint) (err error) { + if c.state.State == ContainerStateUnknown || c.state.State == ContainerStatePaused { + return errors.Wrapf(ErrCtrStateInvalid, "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 + } + } 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() +} + // mountStorage sets up the container's root filesystem // It mounts the image and any other requested mounts // TODO: Add ability to override mount label so we can use this for Mount() too |