Add ability to signal container not just processes

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-04 14:10:50 -08:00
parent 9eb08b8971
commit b5931855a4
5 changed files with 24 additions and 1 deletions

View File

@ -61,6 +61,9 @@ func (s *server) updateContainer(w http.ResponseWriter, r *http.Request) {
}
e := containerd.NewEvent(containerd.UpdateContainerEventType)
e.ID = id
if state.Signal != 0 {
e.Signal = syscall.Signal(state.Signal)
}
e.State = &runtime.State{
Status: runtime.Status(string(state.Status)),
}

View File

@ -19,6 +19,7 @@ type Machine struct {
type ContainerState struct {
Status Status `json:"status,omitempty"`
Signal int `json:"signal,omitempty"`
}
type Container struct {

View File

@ -225,7 +225,14 @@ func (c *libcontainerContainer) getCheckpointPath(name string) string {
func (c *libcontainerContainer) Checkpoint(cp runtime.Checkpoint) error {
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
}
if err := c.c.Checkpoint(opts); err != nil {

View File

@ -10,6 +10,7 @@ var (
ErrNotChildProcess = errors.New("containerd: not a child process for container")
ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime")
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.

View File

@ -25,5 +25,16 @@ func (h *UpdateEvent) Handle(e *Event) error {
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
}