Merge branch 'logs'
This commit is contained in:
commit
04f4df9879
16 changed files with 210 additions and 241 deletions
|
@ -17,7 +17,7 @@ func (h *AddProcessEvent) Handle(e *Event) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
l, err := h.s.log(ci.container.Path(), io)
|
l, err := h.s.copyIO(e.Stdin, e.Stdout, e.Stderr, io)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log the error but continue with the other commands
|
// log the error but continue with the other commands
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
@ -30,7 +30,7 @@ func (h *AddProcessEvent) Handle(e *Event) error {
|
||||||
}
|
}
|
||||||
h.s.processes[e.Pid] = &containerInfo{
|
h.s.processes[e.Pid] = &containerInfo{
|
||||||
container: ci.container,
|
container: ci.container,
|
||||||
logger: l,
|
copier: l,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ func (s *apiServer) CreateContainer(ctx context.Context, c *types.CreateContaine
|
||||||
e := containerd.NewEvent(containerd.StartContainerEventType)
|
e := containerd.NewEvent(containerd.StartContainerEventType)
|
||||||
e.ID = c.Id
|
e.ID = c.Id
|
||||||
e.BundlePath = c.BundlePath
|
e.BundlePath = c.BundlePath
|
||||||
|
e.Stdout = c.Stdout
|
||||||
|
e.Stderr = c.Stderr
|
||||||
|
e.Stdin = c.Stdin
|
||||||
if c.Checkpoint != "" {
|
if c.Checkpoint != "" {
|
||||||
e.Checkpoint = &runtime.Checkpoint{
|
e.Checkpoint = &runtime.Checkpoint{
|
||||||
Name: c.Checkpoint,
|
Name: c.Checkpoint,
|
||||||
|
|
|
@ -53,6 +53,7 @@ var _ = math.Inf
|
||||||
type CreateContainerRequest struct {
|
type CreateContainerRequest struct {
|
||||||
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
|
||||||
BundlePath string `protobuf:"bytes,2,opt,name=bundlePath" json:"bundlePath,omitempty"`
|
BundlePath string `protobuf:"bytes,2,opt,name=bundlePath" json:"bundlePath,omitempty"`
|
||||||
|
Stdin string `protobuf:"bytes,3,opt,name=stdin" json:"stdin,omitempty"`
|
||||||
Stdout string `protobuf:"bytes,4,opt,name=stdout" json:"stdout,omitempty"`
|
Stdout string `protobuf:"bytes,4,opt,name=stdout" json:"stdout,omitempty"`
|
||||||
Stderr string `protobuf:"bytes,5,opt,name=stderr" json:"stderr,omitempty"`
|
Stderr string `protobuf:"bytes,5,opt,name=stderr" json:"stderr,omitempty"`
|
||||||
Checkpoint string `protobuf:"bytes,7,opt,name=checkpoint" json:"checkpoint,omitempty"`
|
Checkpoint string `protobuf:"bytes,7,opt,name=checkpoint" json:"checkpoint,omitempty"`
|
||||||
|
@ -711,54 +712,54 @@ var _API_serviceDesc = grpc.ServiceDesc{
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
var fileDescriptor0 = []byte{
|
||||||
// 773 bytes of a gzipped FileDescriptorProto
|
// 782 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0x5d, 0x4f, 0xdc, 0x3a,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0x5f, 0x4f, 0xdb, 0x3e,
|
||||||
0x10, 0xdd, 0x25, 0x9b, 0xfd, 0x98, 0x65, 0xc3, 0x62, 0x60, 0x09, 0xd1, 0xe5, 0x02, 0xb9, 0xb7,
|
0x14, 0x6d, 0x9b, 0xa6, 0x7f, 0x6e, 0x49, 0x28, 0x06, 0x4a, 0x88, 0x7e, 0xfc, 0x80, 0xec, 0x8f,
|
||||||
0x55, 0x9f, 0x10, 0x82, 0x4a, 0xe5, 0xb1, 0x08, 0xaa, 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8, 0x07, 0xb4, 0x58, 0xaf,
|
||||||
0x4a, 0xd3, 0xa6, 0xc2, 0x5e, 0x55, 0x44, 0x5f, 0xe1, 0xc5, 0xac, 0x8b, 0x62, 0x8a, 0x9b, 0xb6,
|
0x60, 0x91, 0x93, 0xe6, 0x38, 0xce, 0x85, 0x52, 0x4e, 0x69, 0x5a, 0x47, 0xec, 0x55, 0x49, 0xf4,
|
||||||
0x05, 0xe6, 0x32, 0x9a, 0x10, 0xef, 0x04, 0xb6, 0x2f, 0x70, 0x80, 0x5f, 0x62, 0x62, 0xaa, 0x84,
|
0x0e, 0x27, 0xb3, 0x26, 0xc9, 0x14, 0x37, 0x1d, 0x1b, 0xac, 0x65, 0x34, 0x29, 0xde, 0x31, 0x6c,
|
||||||
0xce, 0x02, 0xe7, 0xc3, 0x90, 0x01, 0x2e, 0x5f, 0x12, 0x80, 0xff, 0xc1, 0xd6, 0xa5, 0x4f, 0xe8,
|
0x9d, 0xe3, 0x19, 0x7e, 0x2e, 0x13, 0x53, 0x25, 0x74, 0xe7, 0x58, 0xcc, 0x46, 0x06, 0xb8, 0x7c,
|
||||||
0x1f, 0xe1, 0xec, 0x6f, 0x00, 0xc5, 0x01, 0x05, 0xae, 0xa8, 0xf0, 0x93, 0x4f, 0x45, 0xa7, 0x98,
|
0x49, 0x02, 0xbe, 0x80, 0xcd, 0x8b, 0x80, 0xd0, 0xbf, 0xc2, 0x39, 0xdf, 0x00, 0x8a, 0x03, 0x0a,
|
||||||
0x2c, 0xd4, 0x8d, 0x79, 0xa3, 0x86, 0x68, 0x03, 0xc6, 0x69, 0xe8, 0x3f, 0xdd, 0x44, 0xee, 0x03,
|
0x5c, 0xa5, 0xc2, 0x8f, 0x01, 0x95, 0x9d, 0x62, 0xb2, 0x50, 0x2f, 0xe6, 0x8d, 0x1a, 0xa0, 0x75,
|
||||||
0xa6, 0x84, 0x4f, 0xe2, 0x10, 0x4d, 0x40, 0x27, 0x73, 0x1c, 0x04, 0x7c, 0x10, 0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, 0x6b, 0xb5, 0x1c, 0xb5, 0x3b,
|
0xcf, 0x55, 0x5e, 0x70, 0x46, 0x7b, 0xa3, 0x1c, 0x54, 0xb7, 0x0e, 0xa1, 0x27, 0x9e, 0x91, 0x6a,
|
||||||
0x47, 0xdd, 0xbb, 0x3e, 0xff, 0x4d, 0x39, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xd4, 0x82, 0xb4,
|
0x59, 0xe9, 0x55, 0xd9, 0x2b, 0x8b, 0x51, 0xa7, 0x75, 0xd8, 0xbe, 0xed, 0xf1, 0xbf, 0x96, 0xe3,
|
||||||
0x20, 0xb3, 0x08, 0x00, 0x00,
|
0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x36, 0x89, 0xf8, 0xbd, 0xc2, 0x08, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ service API {
|
||||||
message CreateContainerRequest {
|
message CreateContainerRequest {
|
||||||
string id = 1; // ID of container
|
string id = 1; // ID of container
|
||||||
string bundlePath = 2; // path to OCI bundle
|
string bundlePath = 2; // path to OCI bundle
|
||||||
|
string stdin = 3; // path to the file where stdin will be read (optional)
|
||||||
string stdout = 4; // path to file where stdout will be written (optional)
|
string stdout = 4; // path to file where stdout will be written (optional)
|
||||||
string stderr = 5; // path to file where stderr will be written (optional)
|
string stderr = 5; // path to file where stderr will be written (optional)
|
||||||
string checkpoint = 7; // checkpoint name if you want to create immediate checkpoint (optional)
|
string checkpoint = 7; // checkpoint name if you want to create immediate checkpoint (optional)
|
||||||
|
|
|
@ -2,7 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
@ -63,6 +67,10 @@ var StartCommand = cli.Command{
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "checkpoint to start the container from",
|
Usage: "checkpoint to start the container from",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "interactive,i",
|
||||||
|
Usage: "connect to the stdio of the container",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
var (
|
var (
|
||||||
|
@ -75,17 +83,75 @@ var StartCommand = cli.Command{
|
||||||
if id == "" {
|
if id == "" {
|
||||||
fatal("container id cannot be empty", 1)
|
fatal("container id cannot be empty", 1)
|
||||||
}
|
}
|
||||||
c := getClient()
|
r := &types.CreateContainerRequest{
|
||||||
if _, err := c.CreateContainer(netcontext.Background(), &types.CreateContainerRequest{
|
|
||||||
Id: id,
|
Id: id,
|
||||||
BundlePath: path,
|
BundlePath: path,
|
||||||
Checkpoint: context.String("checkpoint"),
|
Checkpoint: context.String("checkpoint"),
|
||||||
}); err != nil {
|
}
|
||||||
|
if context.Bool("interactive") {
|
||||||
|
if err := attachStdio(r); err != nil {
|
||||||
|
fatal(err.Error(), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c := getClient()
|
||||||
|
if _, err := c.CreateContainer(netcontext.Background(), r); err != nil {
|
||||||
fatal(err.Error(), 1)
|
fatal(err.Error(), 1)
|
||||||
}
|
}
|
||||||
|
if stdin != nil {
|
||||||
|
io.Copy(stdin, os.Stdin)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stdin io.WriteCloser
|
||||||
|
|
||||||
|
func attachStdio(r *types.CreateContainerRequest) error {
|
||||||
|
dir, err := ioutil.TempDir("", "ctr-")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, p := range []struct {
|
||||||
|
path string
|
||||||
|
flag int
|
||||||
|
done func(f *os.File)
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
path: filepath.Join(dir, "stdin"),
|
||||||
|
flag: syscall.O_RDWR,
|
||||||
|
done: func(f *os.File) {
|
||||||
|
r.Stdin = filepath.Join(dir, "stdin")
|
||||||
|
stdin = f
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: filepath.Join(dir, "stdout"),
|
||||||
|
flag: syscall.O_RDWR,
|
||||||
|
done: func(f *os.File) {
|
||||||
|
r.Stdout = filepath.Join(dir, "stdout")
|
||||||
|
go io.Copy(os.Stdout, f)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: filepath.Join(dir, "stderr"),
|
||||||
|
flag: syscall.O_RDWR,
|
||||||
|
done: func(f *os.File) {
|
||||||
|
r.Stderr = filepath.Join(dir, "stderr")
|
||||||
|
go io.Copy(os.Stderr, f)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
if err := syscall.Mkfifo(p.path, 0755); err != nil {
|
||||||
|
return fmt.Errorf("mkfifo: %s %v", p.path, err)
|
||||||
|
}
|
||||||
|
f, err := os.OpenFile(p.path, p.flag, 0)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open: %s %v", p.path, err)
|
||||||
|
}
|
||||||
|
p.done(f)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var KillCommand = cli.Command{
|
var KillCommand = cli.Command{
|
||||||
Name: "kill",
|
Name: "kill",
|
||||||
Usage: "send a signal to a container or it's processes",
|
Usage: "send a signal to a container or it's processes",
|
||||||
|
|
60
ctr/logs.go
60
ctr/logs.go
|
@ -1,60 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
|
||||||
"github.com/docker/containerd"
|
|
||||||
)
|
|
||||||
|
|
||||||
var LogsCommand = cli.Command{
|
|
||||||
Name: "logs",
|
|
||||||
Usage: "view binary container logs generated by containerd",
|
|
||||||
Flags: []cli.Flag{
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "follow,f",
|
|
||||||
Usage: "follow/tail the logs",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Action: func(context *cli.Context) {
|
|
||||||
path := context.Args().First()
|
|
||||||
if path == "" {
|
|
||||||
fatal("path to the log cannot be empty", 1)
|
|
||||||
}
|
|
||||||
if err := readLogs(path, context.Bool("follow")); err != nil {
|
|
||||||
fatal(err.Error(), 1)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func readLogs(path string, follow bool) error {
|
|
||||||
f, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
dec := json.NewDecoder(f)
|
|
||||||
for {
|
|
||||||
var msg *containerd.Message
|
|
||||||
if err := dec.Decode(&msg); err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
if follow {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch msg.Stream {
|
|
||||||
case "stdout":
|
|
||||||
os.Stdout.Write(msg.Data)
|
|
||||||
case "stderr":
|
|
||||||
os.Stderr.Write(msg.Data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -37,7 +37,6 @@ func main() {
|
||||||
CheckpointCommand,
|
CheckpointCommand,
|
||||||
ContainersCommand,
|
ContainersCommand,
|
||||||
EventsCommand,
|
EventsCommand,
|
||||||
LogsCommand,
|
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
app.Before = func(context *cli.Context) error {
|
||||||
if context.GlobalBool("debug") {
|
if context.GlobalBool("debug") {
|
||||||
|
|
|
@ -14,9 +14,9 @@ func (h *DeleteEvent) Handle(e *Event) error {
|
||||||
if err := h.deleteContainer(i.container); err != nil {
|
if err := h.deleteContainer(i.container); err != nil {
|
||||||
logrus.WithField("error", err).Error("containerd: deleting container")
|
logrus.WithField("error", err).Error("containerd: deleting container")
|
||||||
}
|
}
|
||||||
if i.logger != nil {
|
if i.copier != nil {
|
||||||
if err := i.logger.Close(); err != nil {
|
if err := i.copier.Close(); err != nil {
|
||||||
logrus.WithField("error", err).Error("containerd: close container logger")
|
logrus.WithField("error", err).Error("containerd: close container copier")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.s.notifySubscribers(&Event{
|
h.s.notifySubscribers(&Event{
|
||||||
|
|
3
event.go
3
event.go
|
@ -36,6 +36,9 @@ type Event struct {
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
ID string
|
ID string
|
||||||
BundlePath string
|
BundlePath string
|
||||||
|
Stdout string
|
||||||
|
Stderr string
|
||||||
|
Stdin string
|
||||||
Pid int
|
Pid int
|
||||||
Status int
|
Status int
|
||||||
Signal os.Signal
|
Signal os.Signal
|
||||||
|
|
2
exit.go
2
exit.go
|
@ -46,7 +46,7 @@ func (h *ExecExitEvent) Handle(e *Event) error {
|
||||||
if err := info.container.RemoveProcess(e.Pid); err != nil {
|
if err := info.container.RemoveProcess(e.Pid); err != nil {
|
||||||
logrus.WithField("error", err).Error("containerd: find container for pid")
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
||||||
}
|
}
|
||||||
if err := info.logger.Close(); err != nil {
|
if err := info.copier.Close(); err != nil {
|
||||||
logrus.WithField("error", err).Error("containerd: close process IO")
|
logrus.WithField("error", err).Error("containerd: close process IO")
|
||||||
}
|
}
|
||||||
delete(h.s.processes, e.Pid)
|
delete(h.s.processes, e.Pid)
|
||||||
|
|
61
io.go
Normal file
61
io.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package containerd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ioConfig struct {
|
||||||
|
StdoutPath string
|
||||||
|
StderrPath string
|
||||||
|
StdinPath string
|
||||||
|
|
||||||
|
Stdin io.WriteCloser
|
||||||
|
Stdout io.ReadCloser
|
||||||
|
Stderr io.ReadCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCopier(i *ioConfig) (*copier, error) {
|
||||||
|
l := &copier{
|
||||||
|
config: i,
|
||||||
|
}
|
||||||
|
if i.StdinPath != "" {
|
||||||
|
f, err := os.OpenFile(i.StdinPath, os.O_RDONLY, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
l.closers = append(l.closers, f)
|
||||||
|
go io.Copy(i.Stdin, f)
|
||||||
|
}
|
||||||
|
if i.StdoutPath != "" {
|
||||||
|
f, err := os.OpenFile(i.StdoutPath, os.O_RDWR, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
l.closers = append(l.closers, f)
|
||||||
|
go io.Copy(f, i.Stdout)
|
||||||
|
}
|
||||||
|
if i.StderrPath != "" {
|
||||||
|
f, err := os.OpenFile(i.StderrPath, os.O_RDWR, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
l.closers = append(l.closers, f)
|
||||||
|
go io.Copy(f, i.Stderr)
|
||||||
|
}
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type copier struct {
|
||||||
|
config *ioConfig
|
||||||
|
closers []io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *copier) Close() (err error) {
|
||||||
|
for _, c := range append(l.closers, l.config.Stdin, l.config.Stdout, l.config.Stderr) {
|
||||||
|
if cerr := c.Close(); err == nil {
|
||||||
|
err = cerr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
110
log.go
110
log.go
|
@ -1,110 +0,0 @@
|
||||||
package containerd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
type logConfig struct {
|
|
||||||
BundlePath string
|
|
||||||
LogSize int64 // in bytes
|
|
||||||
Stdin io.WriteCloser
|
|
||||||
Stdout io.ReadCloser
|
|
||||||
Stderr io.ReadCloser
|
|
||||||
}
|
|
||||||
|
|
||||||
func newLogger(i *logConfig) (*logger, error) {
|
|
||||||
l := &logger{
|
|
||||||
config: i,
|
|
||||||
messages: make(chan *Message, DefaultBufferSize),
|
|
||||||
}
|
|
||||||
f, err := os.OpenFile(
|
|
||||||
filepath.Join(l.config.BundlePath, "logs.json"),
|
|
||||||
os.O_CREATE|os.O_WRONLY|os.O_APPEND,
|
|
||||||
0655,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
l.f = f
|
|
||||||
hout := &logHandler{
|
|
||||||
stream: "stdout",
|
|
||||||
messages: l.messages,
|
|
||||||
}
|
|
||||||
herr := &logHandler{
|
|
||||||
stream: "stderr",
|
|
||||||
messages: l.messages,
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
io.Copy(hout, i.Stdout)
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
io.Copy(herr, i.Stderr)
|
|
||||||
}()
|
|
||||||
l.start()
|
|
||||||
return l, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Stream string `json:"stream"`
|
|
||||||
Timestamp time.Time `json:"timestamp"`
|
|
||||||
Data []byte `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type logger struct {
|
|
||||||
config *logConfig
|
|
||||||
f *os.File
|
|
||||||
wg sync.WaitGroup
|
|
||||||
messages chan *Message
|
|
||||||
}
|
|
||||||
|
|
||||||
type logHandler struct {
|
|
||||||
stream string
|
|
||||||
messages chan *Message
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *logHandler) Write(b []byte) (int, error) {
|
|
||||||
h.messages <- &Message{
|
|
||||||
Stream: h.stream,
|
|
||||||
Timestamp: time.Now(),
|
|
||||||
Data: b,
|
|
||||||
}
|
|
||||||
return len(b), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) start() {
|
|
||||||
l.wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
l.wg.Done()
|
|
||||||
enc := json.NewEncoder(l.f)
|
|
||||||
for m := range l.messages {
|
|
||||||
if err := enc.Encode(m); err != nil {
|
|
||||||
logrus.WithField("error", err).Error("write log message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) Close() (err error) {
|
|
||||||
for _, c := range []io.Closer{
|
|
||||||
l.config.Stdin,
|
|
||||||
l.config.Stdout,
|
|
||||||
l.config.Stderr,
|
|
||||||
} {
|
|
||||||
if cerr := c.Close(); err == nil {
|
|
||||||
err = cerr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(l.messages)
|
|
||||||
l.wg.Wait()
|
|
||||||
if ferr := l.f.Close(); err == nil {
|
|
||||||
err = ferr
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
|
@ -44,6 +44,7 @@ func (i *IO) Close() error {
|
||||||
i.Stdin,
|
i.Stdin,
|
||||||
i.Stdout,
|
i.Stdout,
|
||||||
i.Stderr,
|
i.Stderr,
|
||||||
|
i.Console,
|
||||||
} {
|
} {
|
||||||
if c != nil {
|
if c != nil {
|
||||||
if err := c.Close(); oerr == nil {
|
if err := c.Close(); oerr == nil {
|
||||||
|
@ -51,9 +52,6 @@ func (i *IO) Close() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i.Console != nil {
|
|
||||||
oerr = i.Console.Close()
|
|
||||||
}
|
|
||||||
return oerr
|
return oerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
start.go
3
start.go
|
@ -18,6 +18,9 @@ func (h *StartEvent) Handle(e *Event) error {
|
||||||
Err: e.Err,
|
Err: e.Err,
|
||||||
IO: io,
|
IO: io,
|
||||||
Container: container,
|
Container: container,
|
||||||
|
Stdin: e.Stdin,
|
||||||
|
Stdout: e.Stdout,
|
||||||
|
Stderr: e.Stderr,
|
||||||
}
|
}
|
||||||
if e.Checkpoint != nil {
|
if e.Checkpoint != nil {
|
||||||
task.Checkpoint = e.Checkpoint.Name
|
task.Checkpoint = e.Checkpoint.Name
|
||||||
|
|
|
@ -56,7 +56,7 @@ func NewSupervisor(id, stateDir string, tasks chan *StartTask) (*Supervisor, err
|
||||||
|
|
||||||
type containerInfo struct {
|
type containerInfo struct {
|
||||||
container runtime.Container
|
container runtime.Container
|
||||||
logger *logger
|
copier *copier
|
||||||
}
|
}
|
||||||
|
|
||||||
type Supervisor struct {
|
type Supervisor struct {
|
||||||
|
@ -222,14 +222,16 @@ func (s *Supervisor) SendEvent(evt *Event) {
|
||||||
s.events <- evt
|
s.events <- evt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Supervisor) log(path string, i *runtime.IO) (*logger, error) {
|
func (s *Supervisor) copyIO(stdin, stdout, stderr string, i *runtime.IO) (*copier, error) {
|
||||||
config := &logConfig{
|
config := &ioConfig{
|
||||||
BundlePath: path,
|
|
||||||
Stdin: i.Stdin,
|
Stdin: i.Stdin,
|
||||||
Stdout: i.Stdout,
|
Stdout: i.Stdout,
|
||||||
Stderr: i.Stderr,
|
Stderr: i.Stderr,
|
||||||
|
StdoutPath: stdout,
|
||||||
|
StderrPath: stderr,
|
||||||
|
StdinPath: stdin,
|
||||||
}
|
}
|
||||||
l, err := newLogger(config)
|
l, err := newCopier(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ type StartTask struct {
|
||||||
Container runtime.Container
|
Container runtime.Container
|
||||||
Checkpoint string
|
Checkpoint string
|
||||||
IO *runtime.IO
|
IO *runtime.IO
|
||||||
|
Stdin string
|
||||||
|
Stdout string
|
||||||
|
Stderr string
|
||||||
Err chan error
|
Err chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +37,7 @@ func (w *worker) Start() {
|
||||||
defer w.wg.Done()
|
defer w.wg.Done()
|
||||||
for t := range w.s.tasks {
|
for t := range w.s.tasks {
|
||||||
started := time.Now()
|
started := time.Now()
|
||||||
// start logging the container's stdio
|
l, err := w.s.copyIO(t.Stdin, t.Stdout, t.Stderr, t.IO)
|
||||||
l, err := w.s.log(t.Container.Path(), t.IO)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evt := NewEvent(DeleteEventType)
|
evt := NewEvent(DeleteEventType)
|
||||||
evt.ID = t.Container.ID()
|
evt.ID = t.Container.ID()
|
||||||
|
@ -43,7 +45,7 @@ func (w *worker) Start() {
|
||||||
t.Err <- err
|
t.Err <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.s.containers[t.Container.ID()].logger = l
|
w.s.containers[t.Container.ID()].copier = l
|
||||||
if t.Checkpoint != "" {
|
if t.Checkpoint != "" {
|
||||||
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
||||||
evt := NewEvent(DeleteEventType)
|
evt := NewEvent(DeleteEventType)
|
||||||
|
|
Loading…
Reference in a new issue