github.com/dlintw/docker@v1.5.0-rc4/pkg/sysinfo/sysinfo.go (about)

     1  package sysinfo
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path"
     7  
     8  	log "github.com/Sirupsen/logrus"
     9  	"github.com/docker/libcontainer/cgroups"
    10  )
    11  
    12  type SysInfo struct {
    13  	MemoryLimit            bool
    14  	SwapLimit              bool
    15  	IPv4ForwardingDisabled bool
    16  	AppArmor               bool
    17  }
    18  
    19  func New(quiet bool) *SysInfo {
    20  	sysInfo := &SysInfo{}
    21  	if cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory"); err != nil {
    22  		if !quiet {
    23  			log.Printf("WARNING: %s\n", err)
    24  		}
    25  	} else {
    26  		_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.limit_in_bytes"))
    27  		_, err2 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.soft_limit_in_bytes"))
    28  		sysInfo.MemoryLimit = err1 == nil && err2 == nil
    29  		if !sysInfo.MemoryLimit && !quiet {
    30  			log.Printf("WARNING: Your kernel does not support cgroup memory limit.")
    31  		}
    32  
    33  		_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
    34  		sysInfo.SwapLimit = err == nil
    35  		if !sysInfo.SwapLimit && !quiet {
    36  			log.Printf("WARNING: Your kernel does not support cgroup swap limit.")
    37  		}
    38  	}
    39  
    40  	// Check if AppArmor seems to be enabled on this system.
    41  	if _, err := os.Stat("/sys/kernel/security/apparmor"); os.IsNotExist(err) {
    42  		sysInfo.AppArmor = false
    43  	} else {
    44  		sysInfo.AppArmor = true
    45  	}
    46  	return sysInfo
    47  }