mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use mount to determine the cgroup mountpoint
This commit is contained in:
parent
c42a4179fc
commit
f3e89fae28
2 changed files with 26 additions and 3 deletions
11
runtime.go
11
runtime.go
|
@ -305,11 +305,16 @@ func NewRuntime() (*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())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err1 := ioutil.ReadFile("/sys/fs/cgroup/memory/memory.limit_in_bytes")
|
cgroupMemoryMountpoint, err := FindCgroupMountpoint("memory")
|
||||||
_, err2 := ioutil.ReadFile("/sys/fs/cgroup/memory/memory.soft_limit_in_bytes")
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, 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
|
runtime.capabilities.MemoryLimit = err1 == nil && err2 == nil
|
||||||
|
|
||||||
_, err = ioutil.ReadFile("/sys/fs/cgroup/memory/memeory.memsw.limit_in_bytes")
|
_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memeory.memsw.limit_in_bytes"))
|
||||||
runtime.capabilities.SwapLimit = err == nil
|
runtime.capabilities.SwapLimit = err == nil
|
||||||
|
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
|
|
18
utils.go
18
utils.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -478,3 +479,20 @@ func CompareKernelVersion(a, b *KernelVersionInfo) int {
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindCgroupMountpoint(cgroupType string) (string, error) {
|
||||||
|
output, err := exec.Command("mount").CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
reg := regexp.MustCompile(`^cgroup on (.*) type cgroup \(.*` + cgroupType + `[,\)]`)
|
||||||
|
for _, line := range strings.Split(string(output), "\n") {
|
||||||
|
r := reg.FindStringSubmatch(line)
|
||||||
|
if len(r) == 2 {
|
||||||
|
return r[1], nil
|
||||||
|
}
|
||||||
|
fmt.Printf("line: %s (%d)\n", line, len(r))
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("cgroup mountpoint not found")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue