2015-12-01 18:55:13 +00:00
|
|
|
package containerd
|
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
import "github.com/docker/containerd/runtime"
|
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
type UpdateEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *UpdateEvent) Handle(e *Event) error {
|
|
|
|
container, ok := h.s.containers[e.ID]
|
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
|
|
|
if e.State.Status != "" {
|
|
|
|
switch e.State.Status {
|
2015-12-01 19:56:08 +00:00
|
|
|
case runtime.Running:
|
2015-12-01 18:55:13 +00:00
|
|
|
if err := container.Resume(); err != nil {
|
|
|
|
return ErrUnknownContainerStatus
|
|
|
|
}
|
2015-12-01 19:56:08 +00:00
|
|
|
case runtime.Paused:
|
2015-12-01 18:55:13 +00:00
|
|
|
if err := container.Pause(); err != nil {
|
|
|
|
return ErrUnknownContainerStatus
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return ErrUnknownContainerStatus
|
|
|
|
}
|
|
|
|
}
|
2015-12-04 22:10:50 +00:00
|
|
|
if e.Signal != nil {
|
|
|
|
// signal the pid1/main process of the container
|
|
|
|
processes, err := container.Processes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(processes) == 0 {
|
|
|
|
return ErrProcessNotFound
|
|
|
|
}
|
|
|
|
return processes[0].Signal(e.Signal)
|
|
|
|
}
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|