Selaa lähdekoodia

Merge pull request #40846 from AkihiroSuda/cgroup2-use-systemd-by-default

cgroup2: use "systemd" cgroup driver by default when available
Brian Goff 5 vuotta sitten
vanhempi
commit
763f9e799b
1 muutettua tiedostoa jossa 17 lisäystä ja 1 poistoa
  1. 17 1
      daemon/daemon_unix.go

+ 17 - 1
daemon/daemon_unix.go

@@ -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