Add event support to execution subsystem

The implementation relies on nats.io

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2016-12-11 11:07:32 -08:00
parent dd39b4dcf0
commit 2ef399b315
11 changed files with 441 additions and 125 deletions

View File

@ -113,7 +113,8 @@ func (*CreateContainerRequest) ProtoMessage() {}
func (*CreateContainerRequest) Descriptor() ([]byte, []int) { return fileDescriptorExecution, []int{1} }
type CreateContainerResponse struct {
Container *Container `protobuf:"bytes,1,opt,name=container" json:"container,omitempty"`
Container *Container `protobuf:"bytes,1,opt,name=container" json:"container,omitempty"`
InitProcess *Process `protobuf:"bytes,2,opt,name=initProcess" json:"initProcess,omitempty"`
}
func (m *CreateContainerResponse) Reset() { *m = CreateContainerResponse{} }
@ -347,11 +348,14 @@ func (this *CreateContainerResponse) GoString() string {
if this == nil {
return "nil"
}
s := make([]string, 0, 5)
s := make([]string, 0, 6)
s = append(s, "&execution.CreateContainerResponse{")
if this.Container != nil {
s = append(s, "Container: "+fmt.Sprintf("%#v", this.Container)+",\n")
}
if this.InitProcess != nil {
s = append(s, "InitProcess: "+fmt.Sprintf("%#v", this.InitProcess)+",\n")
}
s = append(s, "}")
return strings.Join(s, "")
}
@ -1182,6 +1186,16 @@ func (m *CreateContainerResponse) MarshalTo(dAtA []byte) (int, error) {
}
i += n1
}
if m.InitProcess != nil {
dAtA[i] = 0x12
i++
i = encodeVarintExecution(dAtA, i, uint64(m.InitProcess.Size()))
n2, err := m.InitProcess.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n2
}
return i, nil
}
@ -1297,11 +1311,11 @@ func (m *StartProcessRequest) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x12
i++
i = encodeVarintExecution(dAtA, i, uint64(m.Process.Size()))
n2, err := m.Process.MarshalTo(dAtA[i:])
n3, err := m.Process.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n2
i += n3
}
if m.Console {
dAtA[i] = 0x18
@ -1353,11 +1367,11 @@ func (m *StartProcessResponse) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0xa
i++
i = encodeVarintExecution(dAtA, i, uint64(m.Process.Size()))
n3, err := m.Process.MarshalTo(dAtA[i:])
n4, err := m.Process.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n3
i += n4
}
return i, nil
}
@ -1457,11 +1471,11 @@ func (m *Process) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x2a
i++
i = encodeVarintExecution(dAtA, i, uint64(m.User.Size()))
n4, err := m.User.MarshalTo(dAtA[i:])
n5, err := m.User.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n4
i += n5
}
if len(m.Cwd) > 0 {
dAtA[i] = 0x32
@ -1513,21 +1527,21 @@ func (m *User) MarshalTo(dAtA []byte) (int, error) {
i = encodeVarintExecution(dAtA, i, uint64(m.Gid))
}
if len(m.AdditionalGids) > 0 {
dAtA6 := make([]byte, len(m.AdditionalGids)*10)
var j5 int
dAtA7 := make([]byte, len(m.AdditionalGids)*10)
var j6 int
for _, num := range m.AdditionalGids {
for num >= 1<<7 {
dAtA6[j5] = uint8(uint64(num)&0x7f | 0x80)
dAtA7[j6] = uint8(uint64(num)&0x7f | 0x80)
num >>= 7
j5++
j6++
}
dAtA6[j5] = uint8(num)
j5++
dAtA7[j6] = uint8(num)
j6++
}
dAtA[i] = 0x1a
i++
i = encodeVarintExecution(dAtA, i, uint64(j5))
i += copy(dAtA[i:], dAtA6[:j5])
i = encodeVarintExecution(dAtA, i, uint64(j6))
i += copy(dAtA[i:], dAtA7[:j6])
}
return i, nil
}
@ -1575,11 +1589,11 @@ func (m *GetContainerResponse) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0xa
i++
i = encodeVarintExecution(dAtA, i, uint64(m.Container.Size()))
n7, err := m.Container.MarshalTo(dAtA[i:])
n8, err := m.Container.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n7
i += n8
}
return i, nil
}
@ -1711,11 +1725,11 @@ func (m *GetProcessResponse) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0xa
i++
i = encodeVarintExecution(dAtA, i, uint64(m.Process.Size()))
n8, err := m.Process.MarshalTo(dAtA[i:])
n9, err := m.Process.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n8
i += n9
}
return i, nil
}
@ -1912,6 +1926,10 @@ func (m *CreateContainerResponse) Size() (n int) {
l = m.Container.Size()
n += 1 + l + sovExecution(uint64(l))
}
if m.InitProcess != nil {
l = m.InitProcess.Size()
n += 1 + l + sovExecution(uint64(l))
}
return n
}
@ -2238,6 +2256,7 @@ func (this *CreateContainerResponse) String() string {
}
s := strings.Join([]string{`&CreateContainerResponse{`,
`Container:` + strings.Replace(fmt.Sprintf("%v", this.Container), "Container", "Container", 1) + `,`,
`InitProcess:` + strings.Replace(fmt.Sprintf("%v", this.InitProcess), "Process", "Process", 1) + `,`,
`}`,
}, "")
return s
@ -2817,6 +2836,39 @@ func (m *CreateContainerResponse) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field InitProcess", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowExecution
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthExecution
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.InitProcess == nil {
m.InitProcess = &Process{}
}
if err := m.InitProcess.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipExecution(dAtA[iNdEx:])
@ -5035,67 +5087,68 @@ var (
func init() { proto.RegisterFile("execution.proto", fileDescriptorExecution) }
var fileDescriptorExecution = []byte{
// 992 bytes of a gzipped FileDescriptorProto
// 1007 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x56, 0xdd, 0x6e, 0xe3, 0x44,
0x14, 0xae, 0xf3, 0xdb, 0x9c, 0xac, 0x77, 0xc3, 0x34, 0x35, 0x56, 0x40, 0x69, 0x31, 0xbb, 0x4b,
0x85, 0x68, 0x5a, 0x02, 0x42, 0x48, 0x5c, 0x6d, 0x9b, 0x10, 0x22, 0x95, 0x90, 0x9d, 0x6c, 0xb4,
0x12, 0x37, 0x95, 0x1b, 0x0f, 0x59, 0x4b, 0xa9, 0x1d, 0x3c, 0x76, 0xb7, 0xdc, 0xf1, 0x08, 0xbc,
0x00, 0x0f, 0xc1, 0x5b, 0xec, 0x25, 0xdc, 0x21, 0x21, 0x55, 0x34, 0x4f, 0xc0, 0x23, 0xa0, 0xf9,
0xb1, 0xf3, 0x63, 0xe7, 0x47, 0x85, 0xed, 0xdd, 0xcc, 0xf1, 0x37, 0x67, 0xbe, 0x73, 0x8e, 0xcf,
0x37, 0x07, 0x1e, 0x91, 0x6b, 0x32, 0x08, 0x7c, 0xdb, 0x75, 0x6a, 0x63, 0xcf, 0xf5, 0x5d, 0xa4,
0x0e, 0x5c, 0xc7, 0x37, 0x6d, 0x87, 0x78, 0x56, 0xed, 0xea, 0xd3, 0xca, 0x7b, 0x43, 0xd7, 0x1d,
0x8e, 0xc8, 0x11, 0xff, 0x78, 0x11, 0xfc, 0x70, 0x44, 0x2e, 0xc7, 0xfe, 0x4f, 0x02, 0x5b, 0x29,
0x0f, 0xdd, 0xa1, 0xcb, 0x97, 0x47, 0x6c, 0x25, 0xac, 0xc6, 0x11, 0xec, 0xf6, 0x7c, 0xd3, 0xf3,
0x4f, 0x43, 0x47, 0x98, 0xfc, 0x18, 0x10, 0xea, 0x23, 0x0d, 0x52, 0xb6, 0xa5, 0x2b, 0xfb, 0xca,
0x41, 0xe1, 0x24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, 0x9f, 0x6c, 0x2c, 0x4f,
0x89, 0xcd, 0x55, 0xe5, 0xc9, 0x1a, 0x94, 0x74, 0xfa, 0x12, 0x1e, 0xcc, 0xf6, 0x0e, 0x31, 0xb6,
0x09, 0x5d, 0x53, 0x8c, 0x6d, 0x62, 0xf3, 0xf1, 0x0d, 0xc0, 0x54, 0xe5, 0xd0, 0x7e, 0x3c, 0xc0,
0x05, 0xa7, 0xef, 0xad, 0x40, 0x48, 0x97, 0x67, 0xa0, 0xce, 0xe9, 0x1d, 0x8a, 0x11, 0x49, 0x50,
0xc3, 0xa5, 0xd7, 0x73, 0x06, 0xea, 0x9c, 0x56, 0xc5, 0xbc, 0x25, 0x29, 0xd9, 0x52, 0x6f, 0xdf,
0x82, 0x3a, 0xa7, 0x27, 0x31, 0x6f, 0x49, 0xea, 0x54, 0x79, 0xbc, 0x1a, 0x14, 0xc4, 0x7d, 0xf2,
0xee, 0x9b, 0xdb, 0xea, 0xd6, 0x1f, 0xb7, 0xd5, 0xad, 0xbf, 0x6f, 0xab, 0xca, 0x8f, 0x93, 0xaa,
0xf2, 0x66, 0x52, 0x55, 0x7e, 0x9b, 0x54, 0x95, 0xbf, 0x26, 0x55, 0xe5, 0x22, 0x27, 0x98, 0x7c,
0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x5f, 0xe2, 0xb2, 0x5f, 0x0d, 0x00, 0x00,
}

View File

@ -38,6 +38,7 @@ message CreateContainerRequest {
message CreateContainerResponse {
Container container = 1;
Process initProcess = 2;
}
message DeleteContainerRequest {

View File

@ -3,9 +3,14 @@ package main
import (
"fmt"
"net"
"net/http"
"net/url"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"google.golang.org/grpc"
@ -15,8 +20,11 @@ import (
api "github.com/docker/containerd/api/execution"
"github.com/docker/containerd/execution"
"github.com/docker/containerd/execution/executors/oci"
// metrics "github.com/docker/go-metrics"
metrics "github.com/docker/go-metrics"
"github.com/urfave/cli"
"github.com/nats-io/go-nats"
stand "github.com/nats-io/nats-streaming-server/server"
)
func main() {
@ -57,6 +65,11 @@ high performance container runtime
Usage: "tcp address to serve metrics on",
Value: "127.0.0.1:7897",
},
cli.StringFlag{
Name: "events-address, e",
Usage: "nats address to serve events on",
Value: nats.DefaultURL,
},
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") {
@ -66,11 +79,29 @@ high performance container runtime
}
app.Action = func(context *cli.Context) error {
signals := make(chan os.Signal, 2048)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
// if address := context.GlobalString("metrics-address"); address != "" {
// go serveMetrics(address)
// }
if address := context.GlobalString("metrics-address"); address != "" {
go serveMetrics(address)
}
eventsURL, err := url.Parse(context.GlobalString("events-address"))
if err != nil {
return err
}
no := stand.DefaultNatsServerOptions
nOpts := &no
nOpts.NoSigs = true
parts := strings.Split(eventsURL.Host, ":")
nOpts.Host = parts[0]
if len(parts) == 2 {
nOpts.Port, err = strconv.Atoi(parts[1])
} else {
nOpts.Port = nats.DefaultPort
}
s := stand.RunServerWithOpts(nil, nOpts)
defer s.Shutdown()
path := context.GlobalString("socket")
if path == "" {
@ -84,10 +115,25 @@ high performance container runtime
var executor execution.Executor
switch context.GlobalString("runtime") {
case "runc":
executor = oci.New(context.GlobalString("root"))
executor, err = oci.New(context.GlobalString("root"))
if err != nil {
return err
}
}
execService, err := execution.New(executor)
// Start events listener
nc, err := nats.Connect(context.GlobalString("events-address"))
if err != nil {
return err
}
nec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
if err != nil {
nc.Close()
return err
}
defer nec.Close()
execService, err := execution.New(executor, nec)
if err != nil {
return err
}
@ -98,6 +144,8 @@ high performance container runtime
for s := range signals {
switch s {
case syscall.SIGUSR1:
dumpStacks()
default:
logrus.WithField("signal", s).Info("containerd: stopping GRPC server")
server.Stop()
@ -122,13 +170,13 @@ func createUnixSocket(path string) (net.Listener, error) {
return net.Listen("unix", path)
}
// func serveMetrics(address string) {
// m := http.NewServeMux()
// m.Handle("/metrics", metrics.Handler())
// if err := http.ListenAndServe(address, m); err != nil {
// logrus.WithError(err).Fatal("containerd: metrics server failure")
// }
// }
func serveMetrics(address string) {
m := http.NewServeMux()
m.Handle("/metrics", metrics.Handler())
if err := http.ListenAndServe(address, m); err != nil {
logrus.WithError(err).Fatal("containerd: metrics server failure")
}
}
func serveGRPC(server *grpc.Server, l net.Listener) {
defer l.Close()
@ -137,3 +185,19 @@ func serveGRPC(server *grpc.Server, l net.Listener) {
logrus.WithError(err).Fatal("containerd: GRPC server failure")
}
}
// DumpStacks dumps the runtime stack.
func dumpStacks() {
var (
buf []byte
stackSize int
)
bufferLen := 16384
for stackSize == len(buf) {
buf = make([]byte, bufferLen)
stackSize = runtime.Stack(buf, true)
bufferLen *= 2
}
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

View File

@ -4,11 +4,12 @@ import (
"fmt"
"os"
"path/filepath"
"time"
gocontext "context"
"github.com/docker/containerd/api/execution"
execEvents "github.com/docker/containerd/execution"
"github.com/nats-io/go-nats"
"github.com/urfave/cli"
)
@ -56,6 +57,27 @@ var runCommand = cli.Command{
return err
}
// setup our event subscriber
nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
return err
}
nec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
if err != nil {
nc.Close()
return err
}
defer nec.Close()
evCh := make(chan *execEvents.ContainerExitEvent, 64)
sub, err := nec.Subscribe(execEvents.ContainersEventsSubjectSubscriber, func(e *execEvents.ContainerExitEvent) {
evCh <- e
})
if err != nil {
return err
}
defer sub.Unsubscribe()
tmpDir, err := getTempDir(id)
if err != nil {
return err
@ -87,18 +109,17 @@ var runCommand = cli.Command{
return err
}
// wait for it to die
var ec uint32
for {
gcr, err := executionService.Get(gocontext.Background(), &execution.GetContainerRequest{
ID: cr.Container.ID,
})
if err != nil {
return err
}
if gcr.Container.Status != execution.Status_RUNNING {
e, more := <-evCh
if !more {
break
}
if e.ID == cr.Container.ID && e.PID == cr.InitProcess.ID {
ec = e.StatusCode
break
}
time.Sleep(100 * time.Millisecond)
}
if _, err := executionService.Delete(gocontext.Background(), &execution.DeleteContainerRequest{
@ -110,6 +131,8 @@ var runCommand = cli.Command{
// Ensure we read all io
fwg.Wait()
os.Exit(int(ec))
return nil
},
}

View File

@ -2,7 +2,7 @@ package execution
import "fmt"
func NewContainer(stateRoot, id, bundle, status string) (*Container, error) {
func NewContainer(stateRoot, id, bundle string) (*Container, error) {
stateDir, err := NewStateDir(stateRoot, id)
if err != nil {
return nil, err
@ -11,7 +11,7 @@ func NewContainer(stateRoot, id, bundle, status string) (*Container, error) {
id: id,
bundle: bundle,
stateDir: stateDir,
status: status,
status: "created",
processes: make(map[string]Process),
}, nil
}

21
execution/events.go Normal file
View File

@ -0,0 +1,21 @@
package execution
type ContainerEvent struct {
ID string
Action string
}
type ContainerExitEvent struct {
ContainerEvent
PID string
StatusCode uint32
}
const (
ContainersEventsSubjectSubscriber = "containerd.execution.container.>"
)
const (
containerEventsSubjectFormat = "containerd.execution.container.%s"
containerProcessEventsSubjectFormat = "containerd.execution.container.%s.%s"
)

View File

@ -0,0 +1,61 @@
package oci
import (
"io"
"os"
"github.com/crosbymichael/go-runc"
)
type OIO struct {
master *os.File // master holds a fd to the created pty if any
console string // console holds the path the the slave linked to master
rio runc.IO // rio holds the open fifos for stdios
}
func newOIO(stdin, stdout, stderr string, console bool) (o OIO, err error) {
defer func() {
if err != nil {
o.cleanup()
}
}()
if o.rio.Stdin, err = os.OpenFile(stdin, os.O_RDONLY, 0); err != nil {
return
}
if o.rio.Stdout, err = os.OpenFile(stdout, os.O_WRONLY, 0); err != nil {
return
}
if o.rio.Stderr, err = os.OpenFile(stderr, os.O_WRONLY, 0); err != nil {
return
}
if console {
o.master, o.console, err = newConsole(0, 0)
if err != nil {
return
}
go io.Copy(o.master, o.rio.Stdin)
go func() {
io.Copy(o.rio.Stdout, o.master)
o.master.Close()
}()
}
return
}
func (o OIO) cleanup() {
if o.master != nil {
o.master.Close()
}
if o.rio.Stdin != nil {
o.rio.Stdin.(*os.File).Close()
}
if o.rio.Stdout != nil {
o.rio.Stdout.(*os.File).Close()
}
if o.rio.Stderr != nil {
o.rio.Stderr.(*os.File).Close()
}
}

View File

@ -14,23 +14,24 @@ import (
var ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
func New(root string) *OCIRuntime {
func New(root string) (*OCIRuntime, error) {
err := SetSubreaper(1)
if err != nil {
return nil, err
}
return &OCIRuntime{
root: root,
runc: &runc.Runc{
Root: filepath.Join(root, "runc"),
},
ios: make(map[string]OIO),
}
}, nil
}
type OCIRuntime struct {
// root holds runtime state information for the containers
root string
runc *runc.Runc
// We need to keep track of the created IO for
ios map[string]OIO
ios map[string]OIO // ios tracks created process io for cleanup purpose on delete
}
func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOpts) (container *execution.Container, err error) {
@ -44,7 +45,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp
}
}()
if container, err = execution.NewContainer(r.root, id, o.Bundle, "created"); err != nil {
if container, err = execution.NewContainer(r.root, id, o.Bundle); err != nil {
return nil, err
}
defer func(c *execution.Container) {
@ -141,11 +142,16 @@ func (r *OCIRuntime) List(ctx context.Context) ([]*execution.Container, error) {
var containers []*execution.Container
for _, c := range runcCs {
container, err := r.load(c)
if err != nil {
return nil, err
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
container, err := r.load(c)
if err != nil {
return nil, err
}
containers = append(containers, container)
}
containers = append(containers, container)
}
return containers, nil

View File

@ -0,0 +1,43 @@
package oci
import (
"syscall"
"unsafe"
)
// PR_SET_CHILD_SUBREAPER allows setting the child subreaper.
// If arg2 is nonzero, set the "child subreaper" attribute of the
// calling process; if arg2 is zero, unset the attribute. When a
// process is marked as a child subreaper, all of the children
// that it creates, and their descendants, will be marked as
// having a subreaper. In effect, a subreaper fulfills the role
// of init(1) for its descendant processes. Upon termination of
// a process that is orphaned (i.e., its immediate parent has
// already terminated) and marked as having a subreaper, the
// nearest still living ancestor subreaper will receive a SIGCHLD
// signal and be able to wait(2) on the process to discover its
// termination status.
const prSetChildSubreaper = 36
// PR_GET_CHILD_SUBREAPER allows retrieving the current child
// subreaper.
// Return the "child subreaper" setting of the caller, in the
// location pointed to by (int *) arg2.
const prGetChildSubreaper = 37
// GetSubreaper returns the subreaper setting for the calling process
func GetSubreaper() (int, error) {
var i uintptr
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prGetChildSubreaper, uintptr(unsafe.Pointer(&i)), 0); err != 0 {
return -1, err
}
return int(i), nil
}
// SetSubreaper sets the value i as the subreaper setting for the calling process
func SetSubreaper(i int) error {
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prSetChildSubreaper, uintptr(i), 0); err != 0 {
return err
}
return nil
}

View File

@ -6,6 +6,7 @@ import (
api "github.com/docker/containerd/api/execution"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/nats-io/go-nats"
"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
)
@ -15,19 +16,20 @@ var (
ErrProcessNotFound = fmt.Errorf("Process not found")
)
func New(executor Executor) (*Service, error) {
func New(executor Executor, nec *nats.EncodedConn) (*Service, error) {
return &Service{
executor: executor,
nec: nec,
}, nil
}
type Service struct {
executor Executor
supervisor *Supervisor
nec *nats.EncodedConn
}
func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
// TODO: write io and bundle path to dir
var err error
container, err := s.executor.Create(ctx, r.ID, CreateOpts{
@ -41,10 +43,14 @@ func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*a
return nil, err
}
s.supervisor.Add(container)
procs := container.Processes()
initProcess := procs[0]
s.monitorProcess(container, initProcess)
return &api.CreateContainerResponse{
Container: toGRPCContainer(container),
Container: toGRPCContainer(container),
InitProcess: toGRPCProcess(initProcess),
}, nil
}
@ -138,7 +144,8 @@ func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest)
if err != nil {
return nil, err
}
s.supervisor.Add(process)
s.monitorProcess(container, process)
return &api.StartProcessResponse{
Process: toGRPCProcess(process),
@ -198,6 +205,43 @@ var (
_ = (api.ExecutionServiceServer)(&Service{})
)
func (s *Service) publishEvent(name string, v interface{}) {
if s.nec == nil {
return
}
err := s.nec.Publish(name, v)
if err != nil {
// TODO: Use logrus?
fmt.Println("Failed to publish '%s:%#v': %v", name, v, err)
}
}
func (s *Service) monitorProcess(container *Container, process Process) {
go func() {
status, err := process.Wait()
if err == nil {
subject := GetContainerProcessEventSubject(container.ID(), process.ID())
s.publishEvent(subject, &ContainerExitEvent{
ContainerEvent: ContainerEvent{
ID: container.ID(),
Action: "exit",
},
PID: process.ID(),
StatusCode: status,
})
}
}()
}
func GetContainerEventSubject(id string) string {
return fmt.Sprintf(containerEventsSubjectFormat, id)
}
func GetContainerProcessEventSubject(containerID, processID string) string {
return fmt.Sprintf(containerProcessEventsSubjectFormat, containerID, processID)
}
func toGRPCContainer(container *Container) *api.Container {
c := &api.Container{
ID: container.ID(),

View File

@ -7,6 +7,6 @@ type waiter interface {
Wait() (uint32, error)
}
func (s *Supervisor) Add(w waiter) {
func (s *Supervisor) Monitor(w waiter, cb func(uint32, error)) {
go cb(w.Wait())
}