From 3f0764fa51829d2c1d821d59e108acb187995070 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 26 Jun 2014 16:44:43 -0700 Subject: [PATCH] Add pause and unpause commands to nsinit Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- nsinit/main.go | 2 ++ nsinit/pause.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 nsinit/pause.go diff --git a/nsinit/main.go b/nsinit/main.go index a3d7bd10..90c4a901 100644 --- a/nsinit/main.go +++ b/nsinit/main.go @@ -32,6 +32,8 @@ func main() { statsCommand, configCommand, nsenterCommand, + pauseCommand, + unpauseCommand, } if err := app.Run(os.Args); err != nil { diff --git a/nsinit/pause.go b/nsinit/pause.go new file mode 100644 index 00000000..6744539c --- /dev/null +++ b/nsinit/pause.go @@ -0,0 +1,49 @@ +package main + +import ( + "log" + + "github.com/codegangsta/cli" + "github.com/docker/libcontainer/cgroups" + "github.com/docker/libcontainer/cgroups/fs" + "github.com/docker/libcontainer/cgroups/systemd" +) + +var pauseCommand = cli.Command{ + Name: "pause", + Usage: "pause the container's processes", + Action: pauseAction, +} + +var unpauseCommand = cli.Command{ + Name: "unpause", + Usage: "unpause the container's processes", + Action: unpauseAction, +} + +func pauseAction(context *cli.Context) { + if err := toggle(cgroups.Frozen); err != nil { + log.Fatal(err) + } +} + +func unpauseAction(context *cli.Context) { + if err := toggle(cgroups.Thawed); err != nil { + log.Fatal(err) + } +} + +func toggle(state cgroups.FreezerState) error { + container, err := loadContainer() + if err != nil { + return err + } + + if systemd.UseSystemd() { + err = systemd.Freeze(container.Cgroups, state) + } else { + err = fs.Freeze(container.Cgroups, state) + } + + return err +}