Add ability to signal container not just processes
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
9eb08b8971
commit
b5931855a4
5 changed files with 24 additions and 1 deletions
|
@ -61,6 +61,9 @@ func (s *server) updateContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
e := containerd.NewEvent(containerd.UpdateContainerEventType)
|
e := containerd.NewEvent(containerd.UpdateContainerEventType)
|
||||||
e.ID = id
|
e.ID = id
|
||||||
|
if state.Signal != 0 {
|
||||||
|
e.Signal = syscall.Signal(state.Signal)
|
||||||
|
}
|
||||||
e.State = &runtime.State{
|
e.State = &runtime.State{
|
||||||
Status: runtime.Status(string(state.Status)),
|
Status: runtime.Status(string(state.Status)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ type Machine struct {
|
||||||
|
|
||||||
type ContainerState struct {
|
type ContainerState struct {
|
||||||
Status Status `json:"status,omitempty"`
|
Status Status `json:"status,omitempty"`
|
||||||
|
Signal int `json:"signal,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
|
|
|
@ -225,7 +225,14 @@ func (c *libcontainerContainer) getCheckpointPath(name string) string {
|
||||||
|
|
||||||
func (c *libcontainerContainer) Checkpoint(cp runtime.Checkpoint) error {
|
func (c *libcontainerContainer) Checkpoint(cp runtime.Checkpoint) error {
|
||||||
opts := c.createCheckpointOpts(cp)
|
opts := c.createCheckpointOpts(cp)
|
||||||
if err := os.MkdirAll(opts.ImagesDirectory, 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(opts.ImagesDirectory), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// mkdir is atomic so if it already exists we can fail
|
||||||
|
if err := os.Mkdir(opts.ImagesDirectory, 0755); err != nil {
|
||||||
|
if os.IsExist(err) {
|
||||||
|
return runtime.ErrCheckpointExists
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.c.Checkpoint(opts); err != nil {
|
if err := c.c.Checkpoint(opts); err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ var (
|
||||||
ErrNotChildProcess = errors.New("containerd: not a child process for container")
|
ErrNotChildProcess = errors.New("containerd: not a child process for container")
|
||||||
ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime")
|
ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime")
|
||||||
ErrCheckpointNotExists = errors.New("containerd: checkpoint does not exist for container")
|
ErrCheckpointNotExists = errors.New("containerd: checkpoint does not exist for container")
|
||||||
|
ErrCheckpointExists = errors.New("containerd: checkpoint already exists")
|
||||||
)
|
)
|
||||||
|
|
||||||
// runtime handles containers, containers handle their own actions.
|
// runtime handles containers, containers handle their own actions.
|
||||||
|
|
11
update.go
11
update.go
|
@ -25,5 +25,16 @@ func (h *UpdateEvent) Handle(e *Event) error {
|
||||||
return ErrUnknownContainerStatus
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue