Move supervisor to it's own package
It allows to keep main namespace cleaner Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
b296d50493
commit
69f8f566a2
24 changed files with 61 additions and 59 deletions
41
supervisor/update.go
Normal file
41
supervisor/update.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package supervisor
|
||||
|
||||
import "github.com/docker/containerd/runtime"
|
||||
|
||||
type UpdateEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
func (h *UpdateEvent) Handle(e *Event) error {
|
||||
i, ok := h.s.containers[e.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
container := i.container
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue