Allow stopping of paused container
When a container is paused, signals are sent once the container has been unpaused. Instead of forcing the user to unpause a container before they can ever send a signal, allow the user to send the signals, and in the case of a stop signal, automatically unpause the container afterwards. This is much safer than unpausing the container first then sending a signal (what a user is currently forced to do), as the container may be paused for very good reasons and should not be unpaused except for stopping. Note that not even SIGKILL is possible while a process is paused, but it is killed the instant it is unpaused. Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: c3feb046b9b1eb606cc7e853d020799eb3800e0e Component: engine
This commit is contained in:
@@ -60,15 +60,11 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
// We could unpause the container for them rather than returning this error
|
||||
if container.Paused {
|
||||
return fmt.Errorf("Container %s is paused. Unpause the container before stopping or killing", container.ID)
|
||||
}
|
||||
|
||||
if !container.Running {
|
||||
return errNotRunning{container.ID}
|
||||
}
|
||||
|
||||
var unpause bool
|
||||
if container.Config.StopSignal != "" && syscall.Signal(sig) != syscall.SIGKILL {
|
||||
containerStopSignal, err := signal.ParseSignal(container.Config.StopSignal)
|
||||
if err != nil {
|
||||
@@ -76,9 +72,11 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
||||
}
|
||||
if containerStopSignal == syscall.Signal(sig) {
|
||||
container.ExitOnNext()
|
||||
unpause = container.Paused
|
||||
}
|
||||
} else {
|
||||
container.ExitOnNext()
|
||||
unpause = container.Paused
|
||||
}
|
||||
|
||||
if !daemon.IsShuttingDown() {
|
||||
@@ -98,11 +96,19 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
|
||||
if strings.Contains(err.Error(), "container not found") ||
|
||||
strings.Contains(err.Error(), "no such process") {
|
||||
logrus.Warnf("container kill failed because of 'container not found' or 'no such process': %s", err.Error())
|
||||
unpause = false
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if unpause {
|
||||
// above kill signal will be sent once resume is finished
|
||||
if err := daemon.containerd.Resume(container.ID); err != nil {
|
||||
logrus.Warn("Cannot unpause container %s: %s", container.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
attributes := map[string]string{
|
||||
"signal": fmt.Sprintf("%d", sig),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user