b5931855a4
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
40 lines
836 B
Go
40 lines
836 B
Go
package containerd
|
|
|
|
import "github.com/docker/containerd/runtime"
|
|
|
|
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 {
|
|
case runtime.Running:
|
|
if err := container.Resume(); err != nil {
|
|
return ErrUnknownContainerStatus
|
|
}
|
|
case runtime.Paused:
|
|
if err := container.Pause(); err != nil {
|
|
return ErrUnknownContainerStatus
|
|
}
|
|
default:
|
|
return ErrUnknownContainerStatus
|
|
}
|
|
}
|
|
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)
|
|
}
|
|
return nil
|
|
}
|