github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/client/fingerprint/cgroup_linux.go (about) 1 // +build linux 2 3 package fingerprint 4 5 import ( 6 "fmt" 7 8 "github.com/opencontainers/runc/libcontainer/cgroups" 9 ) 10 11 const ( 12 cgroupAvailable = "available" 13 ) 14 15 // FindCgroupMountpointDir is used to find the cgroup mount point on a Linux 16 // system. 17 func FindCgroupMountpointDir() (string, error) { 18 mount, err := cgroups.GetCgroupMounts(false) 19 if err != nil { 20 return "", err 21 } 22 // It's okay if the mount point is not discovered 23 if len(mount) == 0 { 24 return "", nil 25 } 26 return mount[0].Mountpoint, nil 27 } 28 29 // Fingerprint tries to find a valid cgroup mount point 30 func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error { 31 mount, err := f.mountPointDetector.MountPoint() 32 if err != nil { 33 f.clearCGroupAttributes(resp) 34 return fmt.Errorf("Failed to discover cgroup mount point: %s", err) 35 } 36 37 // Check if a cgroup mount point was found 38 if mount == "" { 39 40 f.clearCGroupAttributes(resp) 41 42 if f.lastState == cgroupAvailable { 43 f.logger.Info("cgroups are unavailable") 44 } 45 f.lastState = cgroupUnavailable 46 return nil 47 } 48 49 resp.AddAttribute("unique.cgroup.mountpoint", mount) 50 resp.Detected = true 51 52 if f.lastState == cgroupUnavailable { 53 f.logger.Info("cgroups are available") 54 } 55 f.lastState = cgroupAvailable 56 return nil 57 }