package cgroup import ( "os" "path/filepath" "sync" "linkfog.com/public/lib/l" "linkfog.com/public/option" ) var ( HostCgroup = option.HostPrefix + "/sys/fs/cgroup/" DefaultCgroup = "/sys/fs/cgroup/" cgroup2ControllersPaths = []string{ "/proc/1/root/sys/fs/cgroup/cgroup.controllers", filepath.Join(HostCgroup, "cgroup.controllers"), filepath.Join(DefaultCgroup, "cgroup.controllers"), } isCgroup2Once sync.Once isCgroup2 bool ) func IsCgroup2() bool { isCgroup2Once.Do(func() { for _, path := range cgroup2ControllersPaths { if _, err := os.Stat(path); err == nil { l.Info(path, "exist, is cgroup v2") isCgroup2 = true break } } if !isCgroup2 { l.Info("cgroup.controllers not exist, is cgroup v1") } }) return isCgroup2 }