2016-12-14 17:15:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-02-13 18:23:28 +00:00
|
|
|
gocontext "context"
|
2016-12-14 17:15:27 +00:00
|
|
|
"fmt"
|
2017-02-13 18:23:28 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2016-12-14 17:15:27 +00:00
|
|
|
|
2017-04-03 20:14:15 +00:00
|
|
|
"github.com/containerd/containerd/api/services/execution"
|
2016-12-14 17:15:27 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var eventsCommand = cli.Command{
|
|
|
|
Name: "events",
|
|
|
|
Usage: "display containerd events",
|
|
|
|
Action: func(context *cli.Context) error {
|
2017-02-13 18:23:28 +00:00
|
|
|
containers, err := getExecutionService(context)
|
2016-12-14 17:15:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
events, err := containers.Events(gocontext.Background(), &execution.EventsRequest{})
|
2016-12-14 17:15:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
|
|
|
|
fmt.Fprintln(w, "TYPE\tID\tPID\tEXIT_STATUS")
|
2016-12-14 17:15:27 +00:00
|
|
|
for {
|
2017-02-13 18:23:28 +00:00
|
|
|
e, err := events.Recv()
|
2016-12-14 17:15:27 +00:00
|
|
|
if err != nil {
|
2017-02-13 18:23:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w,
|
|
|
|
"%s\t%s\t%d\t%d\n",
|
|
|
|
e.Type.String(),
|
|
|
|
e.ID,
|
|
|
|
e.Pid,
|
|
|
|
e.ExitStatus,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.Flush(); err != nil {
|
|
|
|
return err
|
2016-12-14 17:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|