moby/libcontainerd/client_shutdownrestore_linux.go
Tonis Tiigi 1e36e346db Fix already active error on restoring from ungraceful restart
On killing the processes that were still running
after ungraceful restart, containerd can’t fully
exit the process if the fifos have not been fully
read. In this case process was just marked as exited
and not removed from the internal containers array.

Fixes #22913

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2016-05-26 16:19:11 -07:00

46 lines
1.1 KiB
Go

// +build !experimental
package libcontainerd
import (
"syscall"
"time"
"github.com/Sirupsen/logrus"
)
func (clnt *client) Restore(containerID string, options ...CreateOption) error {
w := clnt.getOrCreateExitNotifier(containerID)
defer w.close()
cont, err := clnt.getContainerdContainer(containerID)
if err == nil && cont.Status != "stopped" {
clnt.lock(cont.Id)
container := clnt.newContainer(cont.BundlePath)
container.systemPid = systemPid(cont)
clnt.appendContainer(container)
clnt.unlock(cont.Id)
container.discardFifos()
if err := clnt.Signal(containerID, int(syscall.SIGTERM)); err != nil {
logrus.Errorf("error sending sigterm to %v: %v", containerID, err)
}
select {
case <-time.After(10 * time.Second):
if err := clnt.Signal(containerID, int(syscall.SIGKILL)); err != nil {
logrus.Errorf("error sending sigkill to %v: %v", containerID, err)
}
select {
case <-time.After(2 * time.Second):
case <-w.wait():
return nil
}
case <-w.wait():
return nil
}
}
clnt.deleteContainer(containerID)
return clnt.setExited(containerID)
}