Improve process addition and removal
Signed-off-by: Michael Crosby <crosbymichael@gmail.com> implement pause and resume Add godeps Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Add readme Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -26,6 +26,7 @@ func NewSupervisor(stateDir string, concurrency int) (*Supervisor, error) {
|
||||
s := &Supervisor{
|
||||
stateDir: stateDir,
|
||||
containers: make(map[string]Container),
|
||||
processes: make(map[int]Container),
|
||||
runtime: runtime,
|
||||
tasks: make(chan *startTask, concurrency*100),
|
||||
journal: j,
|
||||
@@ -43,6 +44,8 @@ type Supervisor struct {
|
||||
|
||||
containers map[string]Container
|
||||
|
||||
processes map[int]Container
|
||||
|
||||
runtime Runtime
|
||||
|
||||
journal *journal
|
||||
@@ -76,6 +79,16 @@ func (s *Supervisor) Start(events chan *Event) error {
|
||||
case ExitEventType:
|
||||
logrus.WithFields(logrus.Fields{"pid": e.Pid, "status": e.Status}).
|
||||
Debug("containerd: process exited")
|
||||
// is it the child process of a container
|
||||
if container, ok := s.processes[e.Pid]; ok {
|
||||
if err := container.RemoveProcess(e.Pid); err != nil {
|
||||
logrus.WithField("error", err).Error("containerd: find container for pid")
|
||||
}
|
||||
delete(s.processes, e.Pid)
|
||||
close(e.Err)
|
||||
continue
|
||||
}
|
||||
// is it the main container's process
|
||||
container, err := s.getContainerForPid(e.Pid)
|
||||
if err != nil {
|
||||
if err != errNoContainerForPid {
|
||||
@@ -143,6 +156,30 @@ func (s *Supervisor) Start(events chan *Event) error {
|
||||
e.Err <- err
|
||||
continue
|
||||
}
|
||||
s.processes[e.Pid] = container
|
||||
case UpdateContainerEventType:
|
||||
container, ok := s.containers[e.ID]
|
||||
if !ok {
|
||||
e.Err <- ErrContainerNotFound
|
||||
continue
|
||||
}
|
||||
if e.State.Status != "" {
|
||||
switch e.State.Status {
|
||||
case Running:
|
||||
if err := container.Resume(); err != nil {
|
||||
e.Err <- ErrUnknownContainerStatus
|
||||
continue
|
||||
}
|
||||
case Paused:
|
||||
if err := container.Pause(); err != nil {
|
||||
e.Err <- ErrUnknownContainerStatus
|
||||
continue
|
||||
}
|
||||
default:
|
||||
e.Err <- ErrUnknownContainerStatus
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
close(e.Err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user