From ec4b6e0bc3f3e2a55769bb3e00e3d32cf14c617c Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Sat, 11 Apr 2015 00:28:07 -0400 Subject: [PATCH] nsinit: Add a flag to enable system support for cgroups Signed-off-by: Mrunal Patel --- nsinit/exec.go | 1 + nsinit/utils.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nsinit/exec.go b/nsinit/exec.go index 9d302aa31..cf40a5951 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -23,6 +23,7 @@ var execCommand = cli.Command{ Action: execAction, Flags: append([]cli.Flag{ cli.BoolFlag{Name: "tty,t", Usage: "allocate a TTY to the container"}, + cli.BoolFlag{Name: "systemd", Usage: "Use systemd for managing cgroups, if available"}, cli.StringFlag{Name: "id", Value: "nsinit", Usage: "specify the ID for a container"}, cli.StringFlag{Name: "config", Value: "", Usage: "path to the configuration file"}, cli.StringFlag{Name: "user,u", Value: "root", Usage: "set the user, uid, and/or gid for the process"}, diff --git a/nsinit/utils.go b/nsinit/utils.go index 4deca7664..92f0a9d9e 100644 --- a/nsinit/utils.go +++ b/nsinit/utils.go @@ -3,10 +3,12 @@ package main import ( "encoding/json" "fmt" + log "github.com/Sirupsen/logrus" "os" "github.com/codegangsta/cli" "github.com/docker/libcontainer" + "github.com/docker/libcontainer/cgroups/systemd" "github.com/docker/libcontainer/configs" ) @@ -29,7 +31,15 @@ func loadConfig(context *cli.Context) (*configs.Config, error) { } func loadFactory(context *cli.Context) (libcontainer.Factory, error) { - return libcontainer.New(context.GlobalString("root"), libcontainer.Cgroupfs) + cgm := libcontainer.Cgroupfs + if context.Bool("systemd") { + if systemd.UseSystemd() { + cgm = libcontainer.SystemdCgroups + } else { + log.Warn("systemd cgroup flag passed, but systemd support for managing cgroups is not available.") + } + } + return libcontainer.New(context.GlobalString("root"), cgm) } func getContainer(context *cli.Context) (libcontainer.Container, error) {