mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
cgroup2: use "systemd" cgroup driver by default when available
The "systemd" cgroup driver is always preferred over "cgroupfs" on systemd-based hosts. This commit does not affect cgroup v1 hosts. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
parent
ba8129b28a
commit
4714ab5d6c
1 changed files with 17 additions and 1 deletions
|
@ -635,7 +635,23 @@ func VerifyCgroupDriver(config *config.Config) error {
|
||||||
|
|
||||||
// UsingSystemd returns true if cli option includes native.cgroupdriver=systemd
|
// UsingSystemd returns true if cli option includes native.cgroupdriver=systemd
|
||||||
func UsingSystemd(config *config.Config) bool {
|
func UsingSystemd(config *config.Config) bool {
|
||||||
return getCD(config) == cgroupSystemdDriver
|
if getCD(config) == cgroupSystemdDriver {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// On cgroup v2 hosts, default to systemd driver
|
||||||
|
if getCD(config) == "" && cgroups.IsCgroup2UnifiedMode() && IsRunningSystemd() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsRunningSystemd is from https://github.com/opencontainers/runc/blob/46be7b612e2533c494e6a251111de46d8e286ed5/libcontainer/cgroups/systemd/common.go#L27-L33
|
||||||
|
func IsRunningSystemd() bool {
|
||||||
|
fi, err := os.Lstat("/run/systemd/system")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return fi.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifyPlatformContainerSettings performs platform-specific validation of the
|
// verifyPlatformContainerSettings performs platform-specific validation of the
|
||||||
|
|
Loading…
Add table
Reference in a new issue