Skip to content

Commit

Permalink
Merge pull request openshift#56 from crosbymichael/nsinit-pause
Browse files Browse the repository at this point in the history
Add pause and unpause commands to nsinit
  • Loading branch information
vmarmol committed Jun 27, 2014
2 parents 14567ad + 3f0764f commit 77c5125
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nsinit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func main() {
statsCommand,
configCommand,
nsenterCommand,
pauseCommand,
unpauseCommand,
}

if err := app.Run(os.Args); err != nil {
Expand Down
49 changes: 49 additions & 0 deletions nsinit/pause.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 77c5125

Please sign in to comment.