2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
import (
|
|
|
|
"time"
|
2015-12-01 19:56:08 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UpdateTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
State runtime.State
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) updateContainer(t *UpdateTask) error {
|
|
|
|
i, ok := s.containers[t.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-02-17 18:55:54 +00:00
|
|
|
if t.State != "" {
|
|
|
|
switch t.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
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
s.notifySubscribers(Event{
|
|
|
|
ID: t.ID,
|
2016-02-12 01:26:24 +00:00
|
|
|
Type: "resume",
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
})
|
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
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
s.notifySubscribers(Event{
|
|
|
|
ID: t.ID,
|
2016-02-12 01:26:24 +00:00
|
|
|
Type: "pause",
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
})
|
2015-12-01 18:55:13 +00:00
|
|
|
default:
|
|
|
|
return ErrUnknownContainerStatus
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 22:21:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type UpdateProcessTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
PID string
|
|
|
|
CloseStdin bool
|
|
|
|
Width int
|
|
|
|
Height int
|
2016-02-02 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) updateProcess(t *UpdateProcessTask) error {
|
|
|
|
i, ok := s.containers[t.ID]
|
2016-02-02 22:21:25 +00:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
|
|
|
processes, err := i.container.Processes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var process runtime.Process
|
|
|
|
for _, p := range processes {
|
2016-02-17 18:55:54 +00:00
|
|
|
if p.ID() == t.PID {
|
2016-02-02 22:21:25 +00:00
|
|
|
process = p
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if process == nil {
|
|
|
|
return ErrProcessNotFound
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
if t.CloseStdin {
|
2016-02-02 22:21:25 +00:00
|
|
|
if err := process.CloseStdin(); err != nil {
|
2016-02-01 19:02:41 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-02-02 22:21:25 +00:00
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
if t.Width > 0 || t.Height > 0 {
|
|
|
|
if err := process.Resize(t.Width, t.Height); err != nil {
|
2016-02-02 22:21:25 +00:00
|
|
|
return err
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
2015-12-04 22:10:50 +00:00
|
|
|
}
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|