github.com/rawahars/moby@v24.0.4+incompatible/libcontainerd/supervisor/remote_daemon_linux.go (about)

     1  package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"syscall"
     7  	"time"
     8  
     9  	"github.com/containerd/containerd/defaults"
    10  	"github.com/docker/docker/pkg/process"
    11  )
    12  
    13  const (
    14  	sockFile      = "containerd.sock"
    15  	debugSockFile = "containerd-debug.sock"
    16  )
    17  
    18  func (r *remote) setDefaults() {
    19  	if r.GRPC.Address == "" {
    20  		r.GRPC.Address = filepath.Join(r.stateDir, sockFile)
    21  	}
    22  	if r.GRPC.MaxRecvMsgSize == 0 {
    23  		r.GRPC.MaxRecvMsgSize = defaults.DefaultMaxRecvMsgSize
    24  	}
    25  	if r.GRPC.MaxSendMsgSize == 0 {
    26  		r.GRPC.MaxSendMsgSize = defaults.DefaultMaxSendMsgSize
    27  	}
    28  	if r.Debug.Address == "" {
    29  		r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
    30  	}
    31  }
    32  
    33  func (r *remote) stopDaemon() {
    34  	// Ask the daemon to quit
    35  	syscall.Kill(r.daemonPid, syscall.SIGTERM)
    36  	// Wait up to 15secs for it to stop
    37  	for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
    38  		if !process.Alive(r.daemonPid) {
    39  			break
    40  		}
    41  		time.Sleep(time.Second)
    42  	}
    43  
    44  	if process.Alive(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  
    50  func (r *remote) killDaemon() {
    51  	// Try to get a stack trace
    52  	syscall.Kill(r.daemonPid, syscall.SIGUSR1)
    53  	<-time.After(100 * time.Millisecond)
    54  	process.Kill(r.daemonPid)
    55  }
    56  
    57  func (r *remote) platformCleanup() {
    58  	_ = os.Remove(r.Address())
    59  }