Detect systemd with cgroup hierarchy.
The previous approach was brittle from within a container and was inconsistend. Fixes #666
This commit is contained in:
parent
c3f15e3b6a
commit
53bcd977b5
@ -24,7 +24,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/libcontainer/cgroups"
|
"github.com/docker/libcontainer/cgroups"
|
||||||
"github.com/docker/libcontainer/cgroups/systemd"
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/google/cadvisor/container"
|
"github.com/google/cadvisor/container"
|
||||||
@ -55,16 +54,19 @@ var check = sync.Once{}
|
|||||||
|
|
||||||
func UseSystemd() bool {
|
func UseSystemd() bool {
|
||||||
check.Do(func() {
|
check.Do(func() {
|
||||||
// run and initialize useSystemd
|
useSystemd = false
|
||||||
useSystemd = systemd.UseSystemd()
|
|
||||||
if !useSystemd {
|
// Check for system.slice in systemd and cpu cgroup.
|
||||||
// Second attempt at checking for systemd, check for a "name=systemd" cgroup.
|
for _, cgroupType := range []string{"name=systemd", "cpu"} {
|
||||||
mnt, err := cgroups.FindCgroupMountpoint("cpu")
|
mnt, err := cgroups.FindCgroupMountpoint(cgroupType)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// systemd presence does not mean systemd controls cgroups.
|
// systemd presence does not mean systemd controls cgroups.
|
||||||
// If system.slice cgroup exists, then systemd is taking control.
|
// If system.slice cgroup exists, then systemd is taking control.
|
||||||
// This breaks if user creates system.slice manually :)
|
// This breaks if user creates system.slice manually :)
|
||||||
useSystemd = utils.FileExists(mnt + "/system.slice")
|
if utils.FileExists(path.Join(mnt, "system.slice")) {
|
||||||
|
useSystemd = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user