2014-01-15 17:36:13 -05:00
|
|
|
package sysinfo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
2014-05-14 18:21:44 -04:00
|
|
|
|
2014-10-27 13:45:38 -04:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2014-06-10 22:58:15 -04:00
|
|
|
"github.com/docker/libcontainer/cgroups"
|
2014-01-15 17:36:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type SysInfo struct {
|
|
|
|
MemoryLimit bool
|
|
|
|
SwapLimit bool
|
|
|
|
IPv4ForwardingDisabled bool
|
|
|
|
AppArmor bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(quiet bool) *SysInfo {
|
|
|
|
sysInfo := &SysInfo{}
|
|
|
|
if cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory"); err != nil {
|
|
|
|
if !quiet {
|
|
|
|
log.Printf("WARNING: %s\n", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.limit_in_bytes"))
|
|
|
|
_, err2 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.soft_limit_in_bytes"))
|
|
|
|
sysInfo.MemoryLimit = err1 == nil && err2 == nil
|
|
|
|
if !sysInfo.MemoryLimit && !quiet {
|
|
|
|
log.Printf("WARNING: Your kernel does not support cgroup memory limit.")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
|
|
|
|
sysInfo.SwapLimit = err == nil
|
|
|
|
if !sysInfo.SwapLimit && !quiet {
|
|
|
|
log.Printf("WARNING: Your kernel does not support cgroup swap limit.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if AppArmor seems to be enabled on this system.
|
|
|
|
if _, err := os.Stat("/sys/kernel/security/apparmor"); os.IsNotExist(err) {
|
|
|
|
sysInfo.AppArmor = false
|
|
|
|
} else {
|
|
|
|
sysInfo.AppArmor = true
|
|
|
|
}
|
|
|
|
return sysInfo
|
|
|
|
}
|