mirror of https://github.com/docker/docs.git
Check if the containers are really running when starting docker
This commit is contained in:
parent
a6779bcae2
commit
3dcaf20d6b
20
runtime.go
20
runtime.go
|
@ -7,8 +7,10 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -132,6 +134,23 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
if err := validateId(container.Id); err != nil {
|
if err := validateId(container.Id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: if the container is supposed to be running but is not, auto restart it?
|
||||||
|
// If the container is supposed to be running, make sure of if
|
||||||
|
if container.State.Running {
|
||||||
|
if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
if !strings.Contains(string(output), "RUNNING") {
|
||||||
|
Debugf("Container %s was supposed to be running be is not.", container.Id)
|
||||||
|
container.State.Running = false
|
||||||
|
if err := container.ToDisk(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
container.runtime = runtime
|
container.runtime = runtime
|
||||||
// Setup state lock (formerly in newState()
|
// Setup state lock (formerly in newState()
|
||||||
lock := new(sync.Mutex)
|
lock := new(sync.Mutex)
|
||||||
|
@ -259,7 +278,6 @@ func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
||||||
// If the auth file does not exist, keep going
|
// If the auth file does not exist, keep going
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
root: root,
|
root: root,
|
||||||
repository: runtimeRepo,
|
repository: runtimeRepo,
|
||||||
|
|
Loading…
Reference in New Issue