Add ability to signal container not just processes
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		| @@ -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)), | ||||
| 	} | ||||
|   | ||||
| @@ -19,6 +19,7 @@ type Machine struct { | ||||
|  | ||||
| type ContainerState struct { | ||||
| 	Status Status `json:"status,omitempty"` | ||||
| 	Signal int    `json:"signal,omitempty"` | ||||
| } | ||||
|  | ||||
| type Container struct { | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
							
								
								
									
										11
									
								
								update.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								update.go
									
									
									
									
									
								
							| @@ -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 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby