Improve wait for lxc and driver interface

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-01-13 17:17:59 -08:00
parent c2b602b2ac
commit 8c9f62d037
5 changed files with 14 additions and 42 deletions

View file

@ -1115,7 +1115,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
if container.process == nil {
// This happends when you have a GHOST container with lxc
err = container.runtime.Wait(container, 0)
err = container.runtime.WaitGhost(container)
} else {
exitCode, err = container.runtime.Run(container, callback)
}

View file

@ -3,7 +3,6 @@ package chroot
import (
"github.com/dotcloud/docker/execdriver"
"os/exec"
"time"
)
type driver struct {
@ -55,8 +54,8 @@ func (d *driver) Kill(p *execdriver.Process, sig int) error {
return p.Process.Kill()
}
func (d *driver) Wait(id string, duration time.Duration) error {
panic("No Implemented")
func (d *driver) Wait(id string) error {
panic("Not Implemented")
}
func (d *driver) Version() string {

View file

@ -4,7 +4,6 @@ import (
"errors"
"os/exec"
"syscall"
"time"
)
var (
@ -18,7 +17,7 @@ type Driver interface {
Run(c *Process, startCallback StartCallback) (int, error) // Run executes the process and blocks until the process exits and returns the exit code
Kill(c *Process, sig int) error
// TODO: @crosbymichael @creack wait should probably return the exit code
Wait(id string, duration time.Duration) error // Wait on an out of process...process - lxc ghosts
Wait(id string) error // Wait on an out of process...process - lxc ghosts
Version() string
Name() string
}

View file

@ -133,24 +133,17 @@ func (d *driver) Kill(c *execdriver.Process, sig int) error {
return d.kill(c, sig)
}
func (d *driver) Wait(id string, duration time.Duration) error {
var (
killer bool
done = d.waitLxc(id, &killer)
)
if duration > 0 {
select {
case err := <-done:
func (d *driver) Wait(id string) error {
for {
output, err := exec.Command("lxc-info", "-n", id).CombinedOutput()
if err != nil {
return err
case <-time.After(duration):
killer = true
return execdriver.ErrWaitTimeoutReached
}
} else {
return <-done
if !strings.Contains(string(output), "RUNNING") {
return nil
}
time.Sleep(500 * time.Millisecond)
}
return nil
}
func (d *driver) Version() string {
@ -207,25 +200,6 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
return execdriver.ErrNotRunning
}
func (d *driver) waitLxc(id string, kill *bool) <-chan error {
done := make(chan error)
go func() {
for *kill {
output, err := exec.Command("lxc-info", "-n", id).CombinedOutput()
if err != nil {
done <- err
return
}
if !strings.Contains(string(output), "RUNNING") {
done <- err
return
}
time.Sleep(500 * time.Millisecond)
}
}()
return done
}
func (d *driver) getInfo(c *execdriver.Process) ([]byte, error) {
return exec.Command("lxc-info", "-s", "-n", c.ID).CombinedOutput()
}

View file

@ -849,8 +849,8 @@ func (runtime *Runtime) Kill(c *Container, sig int) error {
return runtime.execDriver.Kill(c.process, sig)
}
func (runtime *Runtime) Wait(c *Container, duration time.Duration) error {
return runtime.execDriver.Wait(c.ID, duration)
func (runtime *Runtime) WaitGhost(c *Container) error {
return runtime.execDriver.Wait(c.ID)
}
// Nuke kills all containers then removes all content