Flatten stuff
This commit is contained in:
parent
86ec7e8fd2
commit
412d2b0239
5 changed files with 8 additions and 23 deletions
|
@ -48,7 +48,7 @@ func (s *server) createContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e := &containerd.CreateContainerEvent{
|
e := &containerd.StartContainerEvent{
|
||||||
ID: id,
|
ID: id,
|
||||||
BundlePath: c.BundlePath,
|
BundlePath: c.BundlePath,
|
||||||
Err: make(chan error, 1),
|
Err: make(chan error, 1),
|
||||||
|
|
|
@ -4,6 +4,7 @@ type Container interface {
|
||||||
ID() string
|
ID() string
|
||||||
Start() error
|
Start() error
|
||||||
Pid() (int, error)
|
Pid() (int, error)
|
||||||
|
// Process() Process
|
||||||
SetExited(status int)
|
SetExited(status int)
|
||||||
Delete() error
|
Delete() error
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,6 @@ func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) {
|
||||||
logrus.WithField("signal", s).Debug("containerd: received signal")
|
logrus.WithField("signal", s).Debug("containerd: received signal")
|
||||||
switch s {
|
switch s {
|
||||||
case syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP:
|
case syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP:
|
||||||
supervisor.Stop()
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case syscall.SIGCHLD:
|
case syscall.SIGCHLD:
|
||||||
exits, err := reap()
|
exits, err := reap()
|
||||||
|
|
4
event.go
4
event.go
|
@ -18,12 +18,12 @@ func (e *ExitEvent) String() string {
|
||||||
return "exit event"
|
return "exit event"
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateContainerEvent struct {
|
type StartContainerEvent struct {
|
||||||
ID string
|
ID string
|
||||||
BundlePath string
|
BundlePath string
|
||||||
Err chan error
|
Err chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CreateContainerEvent) String() string {
|
func (c *StartContainerEvent) String() string {
|
||||||
return "create container"
|
return "create container"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,9 @@ package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/rcrowley/go-metrics"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
containerStartTimer = metrics.NewTimer()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSupervisor returns an initialized Process supervisor.
|
// NewSupervisor returns an initialized Process supervisor.
|
||||||
|
@ -19,7 +13,6 @@ func NewSupervisor(stateDir string, concurrency int) (*Supervisor, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// register counters
|
// register counters
|
||||||
metrics.DefaultRegistry.Register("container-start-time", containerStartTimer)
|
|
||||||
runtime, err := NewRuntime(stateDir)
|
runtime, err := NewRuntime(stateDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -36,6 +29,7 @@ type Supervisor struct {
|
||||||
// stateDir is the directory on the system to store container runtime state information.
|
// stateDir is the directory on the system to store container runtime state information.
|
||||||
stateDir string
|
stateDir string
|
||||||
|
|
||||||
|
processes []Process
|
||||||
containers map[string]Container
|
containers map[string]Container
|
||||||
|
|
||||||
runtime Runtime
|
runtime Runtime
|
||||||
|
@ -57,10 +51,8 @@ func (s *Supervisor) Start(events chan Event) error {
|
||||||
logrus.WithField("event", evt).Debug("containerd: processing event")
|
logrus.WithField("event", evt).Debug("containerd: processing event")
|
||||||
switch e := evt.(type) {
|
switch e := evt.(type) {
|
||||||
case *ExitEvent:
|
case *ExitEvent:
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{"pid": e.Pid, "status": e.Status}).
|
||||||
"pid": e.Pid,
|
Debug("containerd: process exited")
|
||||||
"status": e.Status,
|
|
||||||
}).Debug("containerd: process exited")
|
|
||||||
container, err := s.getContainerForPid(e.Pid)
|
container, err := s.getContainerForPid(e.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != errNoContainerForPid {
|
if err != errNoContainerForPid {
|
||||||
|
@ -73,8 +65,7 @@ func (s *Supervisor) Start(events chan Event) error {
|
||||||
if err := container.Delete(); err != nil {
|
if err := container.Delete(); err != nil {
|
||||||
logrus.WithField("error", err).Error("containerd: deleting container")
|
logrus.WithField("error", err).Error("containerd: deleting container")
|
||||||
}
|
}
|
||||||
case *CreateContainerEvent:
|
case *StartContainerEvent:
|
||||||
start := time.Now()
|
|
||||||
container, err := s.runtime.Create(e.ID, e.BundlePath)
|
container, err := s.runtime.Create(e.ID, e.BundlePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Err <- err
|
e.Err <- err
|
||||||
|
@ -86,7 +77,6 @@ func (s *Supervisor) Start(events chan Event) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
e.Err <- nil
|
e.Err <- nil
|
||||||
containerStartTimer.UpdateSince(start)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -114,8 +104,3 @@ func (s *Supervisor) getContainerForPid(pid int) (Container, error) {
|
||||||
func (s *Supervisor) SendEvent(evt Event) {
|
func (s *Supervisor) SendEvent(evt Event) {
|
||||||
s.events <- evt
|
s.events <- evt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop initiates a shutdown of the supervisor killing all processes under supervision.
|
|
||||||
func (s *Supervisor) Stop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue