remote_daemon_linux.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  28. func (r *remote) stopDaemon() {
  29. // Ask the daemon to quit
  30. syscall.Kill(r.daemonPid, syscall.SIGTERM)
  31. // Wait up to 15secs for it to stop
  32. for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
  33. if !system.IsProcessAlive(r.daemonPid) {
  34. break
  35. }
  36. time.Sleep(time.Second)
  37. }
  38. if system.IsProcessAlive(r.daemonPid) {
  39. r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
  40. syscall.Kill(r.daemonPid, syscall.SIGKILL)
  41. }
  42. }
  43. func (r *remote) killDaemon() {
  44. // Try to get a stack trace
  45. syscall.Kill(r.daemonPid, syscall.SIGUSR1)
  46. <-time.After(100 * time.Millisecond)
  47. system.KillProcess(r.daemonPid)
  48. }
  49. func (r *remote) platformCleanup() {
  50. os.Remove(filepath.Join(r.stateDir, sockFile))
  51. }