cgroups: Add systemd implementation of cgroups

This implements cgroup.Apply() using the systemd apis.
We create a transient unit called "docker-$id.scope" that contains
the container processes. We also have a way to set unit specific
properties, currently only defining the Slice to put the
scope in.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
This commit is contained in:
Alexander Larsson
2014-03-27 22:44:31 +01:00
parent 1296d5ce9a
commit 6c7835050e
4 changed files with 199 additions and 1 deletions
@@ -5,6 +5,7 @@ import (
"github.com/dotcloud/docker/pkg/cgroups"
"github.com/dotcloud/docker/pkg/libcontainer"
"github.com/dotcloud/docker/runtime/execdriver"
"github.com/dotcloud/docker/utils"
"os"
)
@@ -59,6 +60,19 @@ func createContainer(c *execdriver.Command) *libcontainer.Container {
container.Cgroups.MemorySwap = c.Resources.MemorySwap
}
if opts, ok := c.Config["unit"]; ok {
props := [][2]string{}
for _, opt := range opts {
key, value, err := utils.ParseKeyValueOpt(opt)
if err == nil {
props = append(props, [2]string{key, value})
} else {
props = append(props, [2]string{opt, ""})
}
}
container.Cgroups.UnitProperties = props
}
// check to see if we are running in ramdisk to disable pivot root
container.NoPivotRoot = os.Getenv("DOCKER_RAMDISK") != ""