Implement journal replay

Add addprocess event for addtional processes

Add more api process information
This commit is contained in:
Michael Crosby
2015-11-10 14:57:10 -08:00
parent 6ff2239019
commit 17d9c10e2d
10 changed files with 296 additions and 62 deletions

85
containerd/journal.go Normal file
View File

@@ -0,0 +1,85 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/crosbymichael/containerd"
)
var JournalCommand = cli.Command{
Name: "journal",
Usage: "interact with the containerd journal",
Subcommands: []cli.Command{
JournalReplyCommand,
},
}
var JournalReplyCommand = cli.Command{
Name: "replay",
Usage: "replay a journal to get containerd's state syncronized after a crash",
Flags: []cli.Flag{
cli.StringFlag{
Name: "addr",
Value: "localhost:8888",
Usage: "address of the containerd daemon",
},
},
Action: func(context *cli.Context) {
if err := replay(context.Args().First(), context.String("addr")); err != nil {
logrus.Fatal(err)
}
},
}
func replay(path, addr string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
dec := json.NewDecoder(f)
var events []*containerd.Event
type entry struct {
Event *containerd.Event `json:"event"`
}
for dec.More() {
var e entry
if err := dec.Decode(&e); err != nil {
if err == io.EOF {
break
}
return err
}
events = append(events, e.Event)
}
c := &http.Client{}
for _, e := range events {
switch e.Type {
case containerd.ExitEventType, containerd.DeleteEventType:
// ignore these types of events
continue
}
data, err := json.Marshal(e)
if err != nil {
return err
}
fmt.Printf("sending %q event\n", e.Type)
r, err := c.Post("http://"+filepath.Join(addr, "event"), "application/json", bytes.NewBuffer(data))
if err != nil {
return err
}
if r.Body != nil {
io.Copy(os.Stdout, r.Body)
r.Body.Close()
}
}
return nil
}

View File

@@ -25,6 +25,7 @@ func main() {
}
app.Commands = []cli.Command{
DaemonCommand,
JournalCommand,
}
app.Flags = []cli.Flag{
cli.BoolFlag{Name: "debug", Usage: "enable debug output in the logs"},