remote_daemon_linux.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/process"
  9. )
  10. const (
  11. binaryName = "containerd"
  12. sockFile = "containerd.sock"
  13. debugSockFile = "containerd-debug.sock"
  14. )
  15. func (r *remote) setDefaults() {
  16. if r.GRPC.Address == "" {
  17. r.GRPC.Address = filepath.Join(r.stateDir, sockFile)
  18. }
  19. if r.GRPC.MaxRecvMsgSize == 0 {
  20. r.GRPC.MaxRecvMsgSize = defaults.DefaultMaxRecvMsgSize
  21. }
  22. if r.GRPC.MaxSendMsgSize == 0 {
  23. r.GRPC.MaxSendMsgSize = defaults.DefaultMaxSendMsgSize
  24. }
  25. if r.Debug.Address == "" {
  26. r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
  27. }
  28. }
  29. func (r *remote) stopDaemon() {
  30. // Ask the daemon to quit
  31. syscall.Kill(r.daemonPid, syscall.SIGTERM)
  32. // Wait up to 15secs for it to stop
  33. for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
  34. if !process.Alive(r.daemonPid) {
  35. break
  36. }
  37. time.Sleep(time.Second)
  38. }
  39. if process.Alive(r.daemonPid) {
  40. r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
  41. syscall.Kill(r.daemonPid, syscall.SIGKILL)
  42. }
  43. }
  44. func (r *remote) killDaemon() {
  45. // Try to get a stack trace
  46. _ = syscall.Kill(r.daemonPid, syscall.SIGUSR1)
  47. <-time.After(100 * time.Millisecond)
  48. _ = process.Kill(r.daemonPid)
  49. }
  50. func (r *remote) platformCleanup() {
  51. _ = os.Remove(r.Address())
  52. }