remote_daemon_linux.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package libcontainerd // import "github.com/docker/docker/libcontainerd"
  2. import (
  3. "os"
  4. "path/filepath"
  5. "syscall"
  6. "time"
  7. "github.com/containerd/containerd/defaults"
  8. "github.com/docker/docker/pkg/system"
  9. )
  10. const (
  11. sockFile = "docker-containerd.sock"
  12. debugSockFile = "docker-containerd-debug.sock"
  13. )
  14. func (r *remote) setDefaults() {
  15. if r.GRPC.Address == "" {
  16. r.GRPC.Address = filepath.Join(r.stateDir, sockFile)
  17. }
  18. if r.GRPC.MaxRecvMsgSize == 0 {
  19. r.GRPC.MaxRecvMsgSize = defaults.DefaultMaxRecvMsgSize
  20. }
  21. if r.GRPC.MaxSendMsgSize == 0 {
  22. r.GRPC.MaxSendMsgSize = defaults.DefaultMaxSendMsgSize
  23. }
  24. if r.Debug.Address == "" {
  25. r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
  26. }
  27. if r.OOMScore == 0 {
  28. r.OOMScore = -999
  29. }
  30. if r.snapshotter == "" {
  31. r.snapshotter = "overlay"
  32. }
  33. }
  34. func (r *remote) stopDaemon() {
  35. // Ask the daemon to quit
  36. syscall.Kill(r.daemonPid, syscall.SIGTERM)
  37. // Wait up to 15secs for it to stop
  38. for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
  39. if !system.IsProcessAlive(r.daemonPid) {
  40. break
  41. }
  42. time.Sleep(time.Second)
  43. }
  44. if system.IsProcessAlive(r.daemonPid) {
  45. r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
  46. syscall.Kill(r.daemonPid, syscall.SIGKILL)
  47. }
  48. }
  49. func (r *remote) platformCleanup() {
  50. os.Remove(filepath.Join(r.stateDir, sockFile))
  51. }