forked from containerd/containerd
/
update.go
41 lines (38 loc) · 854 Bytes
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package containerd
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
}