mirror of https://github.com/docker/docs.git
Merge pull request #482 from dotcloud/move_capabilitie_function
* runtime: Move the capabilities detection into a runtime method
This commit is contained in:
commit
e431dc26f1
39
runtime.go
39
runtime.go
|
@ -354,6 +354,27 @@ func (runtime *Runtime) restore() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) UpdateCapabilities(quiet bool) {
|
||||||
|
if cgroupMemoryMountpoint, err := FindCgroupMountpoint("memory"); err != nil {
|
||||||
|
if !quiet {
|
||||||
|
log.Printf("WARNING: %s\n", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.limit_in_bytes"))
|
||||||
|
_, err2 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.soft_limit_in_bytes"))
|
||||||
|
runtime.capabilities.MemoryLimit = err1 == nil && err2 == nil
|
||||||
|
if !runtime.capabilities.MemoryLimit && !quiet {
|
||||||
|
log.Printf("WARNING: Your kernel does not support cgroup memory limit.")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
|
||||||
|
runtime.capabilities.SwapLimit = err == nil
|
||||||
|
if !runtime.capabilities.SwapLimit && !quiet {
|
||||||
|
log.Printf("WARNING: Your kernel does not support cgroup swap limit.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: harmonize with NewGraph()
|
// FIXME: harmonize with NewGraph()
|
||||||
func NewRuntime(autoRestart bool) (*Runtime, error) {
|
func NewRuntime(autoRestart bool) (*Runtime, error) {
|
||||||
runtime, err := NewRuntimeFromDirectory("/var/lib/docker", autoRestart)
|
runtime, err := NewRuntimeFromDirectory("/var/lib/docker", autoRestart)
|
||||||
|
@ -369,23 +390,7 @@ func NewRuntime(autoRestart bool) (*Runtime, error) {
|
||||||
log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String())
|
log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
runtime.UpdateCapabilities(false)
|
||||||
if cgroupMemoryMountpoint, err := FindCgroupMountpoint("memory"); err != nil {
|
|
||||||
log.Printf("WARNING: %s\n", err)
|
|
||||||
} else {
|
|
||||||
_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.limit_in_bytes"))
|
|
||||||
_, err2 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.soft_limit_in_bytes"))
|
|
||||||
runtime.capabilities.MemoryLimit = err1 == nil && err2 == nil
|
|
||||||
if !runtime.capabilities.MemoryLimit {
|
|
||||||
log.Printf("WARNING: Your kernel does not support cgroup memory limit.")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
|
|
||||||
runtime.capabilities.SwapLimit = err == nil
|
|
||||||
if !runtime.capabilities.SwapLimit {
|
|
||||||
log.Printf("WARNING: Your kernel does not support cgroup swap limit.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ func newTestRuntime() (*Runtime, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
runtime.UpdateCapabilities(true)
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue