diff --git a/libcontainer/container.go b/libcontainer/container.go index a24b71b8452..57385c22583 100644 --- a/libcontainer/container.go +++ b/libcontainer/container.go @@ -30,6 +30,23 @@ const ( Destroyed ) +//Custom type method for returning status as strings +func (s Status) String() string { + switch s { + case Running: + return "Running" + case Pausing: + return "Pausing" + case Paused: + return "Paused" + case Checkpointed: + return "Checkpointed" + case Destroyed: + return "Destroyed" + } + return "" +} + // State represents a running container's state type State struct { // ID is the container ID. diff --git a/main.go b/main.go index 33a86fc52d3..662196ca627 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,7 @@ func main() { pauseCommand, resumeCommand, execCommand, + statusCommand, } app.Before = func(context *cli.Context) error { if context.GlobalBool("debug") { diff --git a/status.go b/status.go new file mode 100644 index 00000000000..29aa8a247c7 --- /dev/null +++ b/status.go @@ -0,0 +1,25 @@ +// +build linux + +package main + +import ( + "fmt" + "github.com/Sirupsen/logrus" + "github.com/codegangsta/cli" +) + +var statusCommand = cli.Command{ + Name: "status", + Usage: "Current status of container", + Action: func(context *cli.Context) { + container, err := getContainer(context) + if err != nil { + fatal(err) + } + status, err := container.Status() + if err != nil { + logrus.Error(err) + } + fmt.Printf("Container ID %s %s\n", context.GlobalString("id"), status) + }, +}