client_shutdownrestore_linux.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // +build !experimental
  2. package libcontainerd
  3. import (
  4. "syscall"
  5. "time"
  6. "github.com/Sirupsen/logrus"
  7. )
  8. func (clnt *client) Restore(containerID string, options ...CreateOption) error {
  9. w := clnt.getOrCreateExitNotifier(containerID)
  10. defer w.close()
  11. cont, err := clnt.getContainerdContainer(containerID)
  12. if err == nil && cont.Status != "stopped" {
  13. clnt.lock(cont.Id)
  14. container := clnt.newContainer(cont.BundlePath)
  15. container.systemPid = systemPid(cont)
  16. clnt.appendContainer(container)
  17. clnt.unlock(cont.Id)
  18. if err := clnt.Signal(containerID, int(syscall.SIGTERM)); err != nil {
  19. logrus.Errorf("error sending sigterm to %v: %v", containerID, err)
  20. }
  21. select {
  22. case <-time.After(10 * time.Second):
  23. if err := clnt.Signal(containerID, int(syscall.SIGKILL)); err != nil {
  24. logrus.Errorf("error sending sigkill to %v: %v", containerID, err)
  25. }
  26. select {
  27. case <-time.After(2 * time.Second):
  28. case <-w.wait():
  29. return nil
  30. }
  31. case <-w.wait():
  32. return nil
  33. }
  34. }
  35. return clnt.setExited(containerID)
  36. }