remote_daemon_linux.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. for key, conf := range r.pluginConfs.Plugins {
  31. if conf == nil {
  32. r.DisabledPlugins = append(r.DisabledPlugins, key)
  33. delete(r.pluginConfs.Plugins, key)
  34. }
  35. }
  36. if r.snapshotter == "" {
  37. r.snapshotter = "overlay"
  38. }
  39. }
  40. func (r *remote) stopDaemon() {
  41. // Ask the daemon to quit
  42. syscall.Kill(r.daemonPid, syscall.SIGTERM)
  43. // Wait up to 15secs for it to stop
  44. for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
  45. if !system.IsProcessAlive(r.daemonPid) {
  46. break
  47. }
  48. time.Sleep(time.Second)
  49. }
  50. if system.IsProcessAlive(r.daemonPid) {
  51. r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
  52. syscall.Kill(r.daemonPid, syscall.SIGKILL)
  53. }
  54. }
  55. func (r *remote) platformCleanup() {
  56. os.Remove(filepath.Join(r.stateDir, sockFile))
  57. }