Cleanup + add Info to driver in order to have specific IsRunning()

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: crosbymichael)
This commit is contained in:
Guillaume J. Charmes 2014-01-15 11:46:25 -08:00 коммит произвёл Michael Crosby
Родитель f7684ea7f6
Коммит 889b4b10ae
5 изменённых файлов: 75 добавлений и 29 удалений

Просмотреть файл

@ -697,17 +697,18 @@ func (container *Container) Start() (err error) {
}
container.waitLock = make(chan struct{})
// Setup pipes
// Setuping pipes and/or Pty
var setup func() error
if container.Config.Tty {
err = container.setupPty()
setup = container.setupPty
} else {
err = container.setupStd()
setup = container.setupStd
}
if err != nil {
if err := setup(); err != nil {
return err
}
waitLock := make(chan struct{})
callbackLock := make(chan struct{})
callback := func(process *execdriver.Process) {
container.State.SetRunning(process.Pid())
if process.Tty {
@ -721,7 +722,7 @@ func (container *Container) Start() (err error) {
if err := container.ToDisk(); err != nil {
utils.Debugf("%s", err)
}
close(waitLock)
close(callbackLock)
}
// We use a callback here instead of a goroutine and an chan for
@ -730,7 +731,7 @@ func (container *Container) Start() (err error) {
// Start should not return until the process is actually running
select {
case <-waitLock:
case <-callbackLock:
case err := <-cErr:
return err
}

Просмотреть файл

@ -7,7 +7,10 @@ import (
"os/exec"
)
const DriverName = "chroot"
const (
DriverName = "chroot"
Version = "0.1"
)
func init() {
execdriver.RegisterDockerInitFct(DriverName, func(args *execdriver.DockerInitArgs) error {
@ -32,10 +35,6 @@ func NewDriver() (*driver, error) {
return &driver{}, nil
}
func (d *driver) Name() string {
return DriverName
}
func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
params := []string{
"chroot",
@ -78,6 +77,14 @@ func (d *driver) Wait(id string) error {
panic("Not Implemented")
}
func (d *driver) Version() string {
return "0.1"
func (d *driver) Info(id string) execdriver.Info {
panic("Not implemented")
}
func (d *driver) Name() string {
return DriverName
}
func (d *driver) Version() string {
return Version
}

Просмотреть файл

@ -51,6 +51,10 @@ type DockerInitArgs struct {
Driver string
}
type Info interface {
IsRunning() bool
}
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
@ -58,6 +62,8 @@ type Driver interface {
Wait(id string) error // Wait on an out of process...process - lxc ghosts
Version() string
Name() string
Info(id string) Info // "temporary" hack (until we move state from core to plugins)
}
// Network settings of the container

Просмотреть файл

@ -221,9 +221,9 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
default:
}
output, err = d.getInfo(c)
output, err = d.getInfo(c.ID)
if err != nil {
output, err = d.getInfo(c)
output, err = d.getInfo(c.ID)
if err != nil {
return err
}
@ -236,8 +236,34 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
return execdriver.ErrNotRunning
}
func (d *driver) getInfo(c *execdriver.Process) ([]byte, error) {
return exec.Command("lxc-info", "-s", "-n", c.ID).CombinedOutput()
func (d *driver) getInfo(id string) ([]byte, error) {
return exec.Command("lxc-info", "-s", "-n", id).CombinedOutput()
}
type info struct {
ID string
driver *driver
}
func (i *info) IsRunning() bool {
var running bool
output, err := i.driver.getInfo(i.ID)
if err != nil {
panic(err)
}
if strings.Contains(string(output), "RUNNING") {
running = true
}
return running
}
func (d *driver) Info(id string) execdriver.Info {
return &info{
ID: id,
driver: d,
}
}
func linkLxcStart(root string) error {

Просмотреть файл

@ -18,7 +18,6 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"regexp"
"sort"
@ -164,11 +163,9 @@ func (runtime *Runtime) Register(container *Container) error {
// if so, then we need to restart monitor and init a new lock
// If the container is supposed to be running, make sure of it
if container.State.IsRunning() {
output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput()
if err != nil {
return err
}
if !strings.Contains(string(output), "RUNNING") {
info := runtime.execDriver.Info(container.ID)
if !info.IsRunning() {
utils.Debugf("Container %s was supposed to be running but is not.", container.ID)
if runtime.config.AutoRestart {
utils.Debugf("Restarting")
@ -736,12 +733,21 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
}
capabilities := NewRuntimeCapabilities(false)
var ed execdriver.Driver
if driver := os.Getenv("EXEC_DRIVER"); driver == "lxc" {
ed, err = lxc.NewDriver(config.Root, capabilities.AppArmor)
} else {
ed, err = chroot.NewDriver()
/*
temporarilly disabled.
*/
if false {
var ed execdriver.Driver
if driver := os.Getenv("EXEC_DRIVER"); driver == "lxc" {
ed, err = lxc.NewDriver(config.Root, capabilities.AppArmor)
} else {
ed, err = chroot.NewDriver()
}
if ed != nil {
}
}
ed, err := lxc.NewDriver(config.Root, capabilities.AppArmor)
if err != nil {
return nil, err
}