remote_daemon_linux.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
  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 = "containerd.sock"
  12. debugSockFile = "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. }
  37. func (r *remote) stopDaemon() {
  38. // Ask the daemon to quit
  39. syscall.Kill(r.daemonPid, syscall.SIGTERM)
  40. // Wait up to 15secs for it to stop
  41. for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
  42. if !system.IsProcessAlive(r.daemonPid) {
  43. break
  44. }
  45. time.Sleep(time.Second)
  46. }
  47. if system.IsProcessAlive(r.daemonPid) {
  48. r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
  49. syscall.Kill(r.daemonPid, syscall.SIGKILL)
  50. }
  51. }
  52. func (r *remote) killDaemon() {
  53. // Try to get a stack trace
  54. syscall.Kill(r.daemonPid, syscall.SIGUSR1)
  55. <-time.After(100 * time.Millisecond)
  56. system.KillProcess(r.daemonPid)
  57. }
  58. func (r *remote) platformCleanup() {
  59. os.Remove(filepath.Join(r.stateDir, sockFile))
  60. }