Add config parameter to change per-container stop timeout during daemon shutdown
This fix tries to add a flag `--stop-timeout` to specify the timeout value (in seconds) for the container to stop before SIGKILL is issued. If stop timeout is not specified then the default timeout (10s) is used. Additional test cases have been added to cover the change. This fix is related to #22471. Another pull request will add `--shutdown-timeout` to daemon for #22471. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Upstream-commit: e66d2108911a2fad016205bdd6bf181f7e822c1c Component: engine
This commit is contained in:
@@ -708,8 +708,8 @@ func (daemon *Daemon) shutdownContainer(c *container.Container) error {
|
||||
if err := daemon.containerUnpause(c); err != nil {
|
||||
return fmt.Errorf("Failed to unpause container %s with error: %v", c.ID, err)
|
||||
}
|
||||
if _, err := c.WaitStop(10 * time.Second); err != nil {
|
||||
logrus.Debugf("container %s failed to exit in 10 seconds of SIGTERM, sending SIGKILL to force", c.ID)
|
||||
if _, err := c.WaitStop(time.Duration(c.StopTimeout()) * time.Second); err != nil {
|
||||
logrus.Debugf("container %s failed to exit in %d second of SIGTERM, sending SIGKILL to force", c.ID, c.StopTimeout())
|
||||
sig, ok := signal.SignalMap["KILL"]
|
||||
if !ok {
|
||||
return fmt.Errorf("System does not support SIGKILL")
|
||||
@@ -721,8 +721,8 @@ func (daemon *Daemon) shutdownContainer(c *container.Container) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// If container failed to exit in 10 seconds of SIGTERM, then using the force
|
||||
if err := daemon.containerStop(c, 10); err != nil {
|
||||
// If container failed to exit in c.StopTimeout() seconds of SIGTERM, then using the force
|
||||
if err := daemon.containerStop(c, c.StopTimeout()); err != nil {
|
||||
return fmt.Errorf("Failed to stop container %s with error: %v", c.ID, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user