Add nsinit command to display oom notifications

This adds the ability to receive OOM notifications for a container via
the `nsinit oom` command.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-01-12 16:37:33 -08:00
parent 9377591781
commit 4bbd44784c
2 changed files with 31 additions and 2 deletions

View File

@ -53,11 +53,12 @@ func main() {
app.Before = preload
app.Commands = []cli.Command{
configCommand,
execCommand,
initCommand,
statsCommand,
configCommand,
oomCommand,
pauseCommand,
statsCommand,
unpauseCommand,
}

28
nsinit/oom.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"log"
"github.com/codegangsta/cli"
"github.com/docker/libcontainer"
)
var oomCommand = cli.Command{
Name: "oom",
Usage: "display oom notifications for a container",
Action: oomAction,
}
func oomAction(context *cli.Context) {
state, err := libcontainer.GetState(dataPath)
if err != nil {
log.Fatal(err)
}
n, err := libcontainer.NotifyOnOOM(state)
if err != nil {
log.Fatal(err)
}
for _ = range n {
log.Printf("OOM notification received")
}
}