github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/client/driver/executor/resource_container_linux.go (about) 1 package executor 2 3 import ( 4 "os" 5 "sync" 6 7 dstructs "github.com/hashicorp/nomad/client/driver/structs" 8 cgroupConfig "github.com/opencontainers/runc/libcontainer/configs" 9 ) 10 11 // resourceContainerContext is a platform-specific struct for managing a 12 // resource container. In the case of Linux, this is used to control Cgroups. 13 type resourceContainerContext struct { 14 groups *cgroupConfig.Cgroup 15 cgPaths map[string]string 16 cgLock sync.Mutex 17 } 18 19 // clientCleanup remoevs this host's Cgroup from the Nomad Client's context 20 func clientCleanup(ic *dstructs.IsolationConfig, pid int) error { 21 if err := DestroyCgroup(ic.Cgroup, ic.CgroupPaths, pid); err != nil { 22 return err 23 } 24 return nil 25 } 26 27 // cleanup removes this host's Cgroup from within an Executor's context 28 func (rc *resourceContainerContext) executorCleanup() error { 29 rc.cgLock.Lock() 30 defer rc.cgLock.Unlock() 31 if err := DestroyCgroup(rc.groups, rc.cgPaths, os.Getpid()); err != nil { 32 return err 33 } 34 return nil 35 } 36 37 func (rc *resourceContainerContext) getIsolationConfig() *dstructs.IsolationConfig { 38 return &dstructs.IsolationConfig{ 39 Cgroup: rc.groups, 40 CgroupPaths: rc.cgPaths, 41 } 42 }