Signed-off-by: John Howard <jhoward@microsoft.com> Move process sorter to new file Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Sort containers by id This will not be the most accurate sorting but atleast the list will be consistent inbetween calls. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Allow runtime to be configurable via daemon start This allows people to pass an alternate name or location to the runtime binary to start containers. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Fix state output for containers Return the proper state/status for a container by checking if the pid is still alive. Also fix the cleanup handling in the shim to make sure containers are not left behind. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Properly wait for container start Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
		
			
				
	
	
		
			82 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package supervisor
 | 
						|
 | 
						|
import (
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/Sirupsen/logrus"
 | 
						|
	"github.com/docker/containerd/runtime"
 | 
						|
)
 | 
						|
 | 
						|
type ExitTask struct {
 | 
						|
	baseTask
 | 
						|
	Process runtime.Process
 | 
						|
}
 | 
						|
 | 
						|
func (s *Supervisor) exit(t *ExitTask) error {
 | 
						|
	start := time.Now()
 | 
						|
	proc := t.Process
 | 
						|
	status, err := proc.ExitStatus()
 | 
						|
	if err != nil {
 | 
						|
		logrus.WithFields(logrus.Fields{
 | 
						|
			"error":     err,
 | 
						|
			"pid":       proc.ID(),
 | 
						|
			"id":        proc.Container().ID(),
 | 
						|
			"systemPid": proc.SystemPid(),
 | 
						|
		}).Error("containerd: get exit status")
 | 
						|
	}
 | 
						|
	logrus.WithFields(logrus.Fields{
 | 
						|
		"pid":       proc.ID(),
 | 
						|
		"status":    status,
 | 
						|
		"id":        proc.Container().ID(),
 | 
						|
		"systemPid": proc.SystemPid(),
 | 
						|
	}).Debug("containerd: process exited")
 | 
						|
 | 
						|
	// if the process is the the init process of the container then
 | 
						|
	// fire a separate event for this process
 | 
						|
	if proc.ID() != runtime.InitProcessID {
 | 
						|
		ne := &ExecExitTask{
 | 
						|
			ID:      proc.Container().ID(),
 | 
						|
			PID:     proc.ID(),
 | 
						|
			Status:  status,
 | 
						|
			Process: proc,
 | 
						|
		}
 | 
						|
		s.SendTask(ne)
 | 
						|
		return nil
 | 
						|
	}
 | 
						|
	container := proc.Container()
 | 
						|
	ne := &DeleteTask{
 | 
						|
		ID:     container.ID(),
 | 
						|
		Status: status,
 | 
						|
		PID:    proc.ID(),
 | 
						|
	}
 | 
						|
	s.SendTask(ne)
 | 
						|
 | 
						|
	ExitProcessTimer.UpdateSince(start)
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
type ExecExitTask struct {
 | 
						|
	baseTask
 | 
						|
	ID      string
 | 
						|
	PID     string
 | 
						|
	Status  int
 | 
						|
	Process runtime.Process
 | 
						|
}
 | 
						|
 | 
						|
func (s *Supervisor) execExit(t *ExecExitTask) error {
 | 
						|
	container := t.Process.Container()
 | 
						|
	// exec process: we remove this process without notifying the main event loop
 | 
						|
	if err := container.RemoveProcess(t.PID); err != nil {
 | 
						|
		logrus.WithField("error", err).Error("containerd: find container for pid")
 | 
						|
	}
 | 
						|
	s.notifySubscribers(Event{
 | 
						|
		Timestamp: time.Now(),
 | 
						|
		ID:        t.ID,
 | 
						|
		Type:      "exit",
 | 
						|
		PID:       t.PID,
 | 
						|
		Status:    t.Status,
 | 
						|
	})
 | 
						|
	return nil
 | 
						|
}
 |