aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-19 15:28:46 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-22 14:49:36 +0000
commit0838c2b984bb0188809eb1cbeba2facb69362eb0 (patch)
tree2b25bdf129a474e6dc2da244c964f0f0d32d422a /libpod
parent86930c829ea27cb72a9d56f5a9dd6384f2844026 (diff)
downloadpodman-0838c2b984bb0188809eb1cbeba2facb69362eb0.tar.gz
podman-0838c2b984bb0188809eb1cbeba2facb69362eb0.tar.bz2
podman-0838c2b984bb0188809eb1cbeba2facb69362eb0.zip
Add ability to start containers in a pod
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #361 Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r--libpod/pod.go61
1 files changed, 59 insertions, 2 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index f2afd1e75..1e224b251 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -73,9 +73,62 @@ func (p *Pod) Init() error {
return ErrNotImplemented
}
-// Start starts all containers within a pod that are not already running
+// Start starts all containers within a pod
+// Containers that are already running or have been paused are ignored
+// If an error is encountered starting any container, Start() will cease
+// starting containers and immediately report an error
+// Start() is not an atomic operation - if an error is reported, containers that
+// have already started will remain running
func (p *Pod) Start() error {
- return ErrNotImplemented
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
+ if !p.valid {
+ return ErrPodRemoved
+ }
+
+ allCtrs, err := p.runtime.state.PodContainers(p)
+ if err != nil {
+ return err
+ }
+
+ // We need to lock all the containers
+ for _, ctr := range allCtrs {
+ ctr.lock.Lock()
+ defer ctr.lock.Unlock()
+
+ if err := ctr.syncContainer(); err != nil {
+ return err
+ }
+ }
+
+ // Send a signal to all containers
+ for _, ctr := range allCtrs {
+ // Ignore containers that are not created or stopped
+ if ctr.state.State != ContainerStateCreated && ctr.state.State != ContainerStateStopped {
+ continue
+ }
+
+ // TODO remove this when we patch conmon to support restarting containers
+ if ctr.state.State == ContainerStateStopped {
+ continue;
+ }
+
+ if err := ctr.runtime.ociRuntime.startContainer(ctr); err != nil {
+ return errors.Wrapf(err, "error starting container %s", ctr.ID())
+ }
+
+ // We can safely assume the container is running
+ ctr.state.State = ContainerStateRunning
+
+ if err := ctr.save(); err != nil {
+ return err
+ }
+
+ logrus.Debugf("Started container %s", ctr.ID())
+ }
+
+ return nil
}
// Stop stops all containers within a pod that are not already stopped
@@ -84,6 +137,8 @@ func (p *Pod) Start() error {
// containers will be ignored.
// If an error is encountered stopping any one container, no further containers
// will be stopped, and an error will immediately be returned.
+// Stop() is not an atomic operation - if an error is encountered, containers
+// which have already been stopped will not be restarted
func (p *Pod) Stop() error {
p.lock.Lock()
defer p.lock.Unlock()
@@ -139,6 +194,8 @@ func (p *Pod) Stop() error {
// running will be ignored.
// If an error is encountered signalling any one container, kill will stop
// and immediately return an error, sending no further signals
+// Kill() is not an atomic operation - if an error is encountered, no further
+// signals will be sent, but some signals may already have been sent
func (p *Pod) Kill(signal uint) error {
p.lock.Lock()
defer p.lock.Unlock()