remote_daemon_linux.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. for key, conf := range r.Plugins {
  28. if conf == nil {
  29. r.DisabledPlugins = append(r.DisabledPlugins, key)
  30. delete(r.Plugins, key)
  31. }
  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) killDaemon() {
  50. // Try to get a stack trace
  51. syscall.Kill(r.daemonPid, syscall.SIGUSR1)
  52. <-time.After(100 * time.Millisecond)
  53. system.KillProcess(r.daemonPid)
  54. }
  55. func (r *remote) platformCleanup() {
  56. os.Remove(filepath.Join(r.stateDir, sockFile))
  57. }