Run conmon under cgroups (systemd)
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
3195f45904
commit
8c0ff7d904
3 changed files with 19 additions and 5 deletions
16
oci/oci.go
16
oci/oci.go
|
@ -103,7 +103,7 @@ func getOCIVersion(name string, args ...string) (string, error) {
|
|||
}
|
||||
|
||||
// CreateContainer creates a container.
|
||||
func (r *Runtime) CreateContainer(c *Container) error {
|
||||
func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error {
|
||||
parentPipe, childPipe, err := newPipe()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating socket pair: %v", err)
|
||||
|
@ -143,6 +143,16 @@ func (r *Runtime) CreateContainer(c *Container) error {
|
|||
// We don't need childPipe on the parent side
|
||||
childPipe.Close()
|
||||
|
||||
// Move conmon to specified cgroup
|
||||
if cgroupParent != "" {
|
||||
if r.cgroupManager == "systemd" {
|
||||
logrus.Infof("Running conmon under slice %s and unitName %s", cgroupParent, createUnitName("ocid", c.name))
|
||||
if err := utils.RunUnderSystemdScope(cmd.Process.Pid, cgroupParent, createUnitName("ocid", c.name)); err != nil {
|
||||
logrus.Warnf("Failed to add conmon to sandbox cgroup: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wait to get container pid from conmon
|
||||
// TODO(mrunalp): Add a timeout here
|
||||
var si *syncInfo
|
||||
|
@ -153,6 +163,10 @@ func (r *Runtime) CreateContainer(c *Container) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func createUnitName(prefix string, name string) string {
|
||||
return fmt.Sprintf("%s-%s.scope", prefix, name)
|
||||
}
|
||||
|
||||
// StartContainer starts a container.
|
||||
func (r *Runtime) StartContainer(c *Container) error {
|
||||
c.opLock.Lock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue