2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
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 {
|
2015-12-11 19:27:33 +00:00
|
|
|
i, ok := h.s.containers[e.ID]
|
2015-12-01 18:55:13 +00:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2015-12-11 19:27:33 +00:00
|
|
|
container := i.container
|
2016-01-27 22:19:10 +00:00
|
|
|
if e.State != "" {
|
|
|
|
switch e.State {
|
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 {
|
2016-02-01 19:02:41 +00:00
|
|
|
// signal the pid1/main process of the container
|
|
|
|
processes, err := container.Processes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, p := range processes {
|
|
|
|
if p.ID() == runtime.InitProcessID {
|
|
|
|
return p.Signal(e.Signal)
|
2016-01-06 21:32:46 +00:00
|
|
|
}
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
return ErrProcessNotFound
|
2015-12-04 22:10:50 +00:00
|
|
|
}
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|