2018-05-23 15:15:21 -04:00
|
|
|
package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
|
2017-09-22 09:52:41 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
2018-05-31 20:03:28 -04:00
|
|
|
"github.com/containerd/containerd/defaults"
|
2017-09-22 09:52:41 -04:00
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-09-21 18:58:34 -04:00
|
|
|
sockFile = "containerd.sock"
|
|
|
|
debugSockFile = "containerd-debug.sock"
|
2017-09-22 09:52:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (r *remote) setDefaults() {
|
|
|
|
if r.GRPC.Address == "" {
|
|
|
|
r.GRPC.Address = filepath.Join(r.stateDir, sockFile)
|
|
|
|
}
|
2018-05-31 20:03:28 -04:00
|
|
|
if r.GRPC.MaxRecvMsgSize == 0 {
|
|
|
|
r.GRPC.MaxRecvMsgSize = defaults.DefaultMaxRecvMsgSize
|
|
|
|
}
|
|
|
|
if r.GRPC.MaxSendMsgSize == 0 {
|
|
|
|
r.GRPC.MaxSendMsgSize = defaults.DefaultMaxSendMsgSize
|
|
|
|
}
|
2017-09-22 09:52:41 -04:00
|
|
|
if r.Debug.Address == "" {
|
|
|
|
r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
|
|
|
|
}
|
2018-06-19 18:53:40 -04:00
|
|
|
|
2021-04-02 11:22:22 -04:00
|
|
|
for key, conf := range r.Plugins {
|
2018-06-19 18:53:40 -04:00
|
|
|
if conf == nil {
|
|
|
|
r.DisabledPlugins = append(r.DisabledPlugins, key)
|
2021-04-02 11:22:22 -04:00
|
|
|
delete(r.Plugins, key)
|
2018-06-19 18:53:40 -04:00
|
|
|
}
|
|
|
|
}
|
2017-09-22 09:52:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) stopDaemon() {
|
|
|
|
// Ask the daemon to quit
|
|
|
|
syscall.Kill(r.daemonPid, syscall.SIGTERM)
|
|
|
|
// Wait up to 15secs for it to stop
|
|
|
|
for i := time.Duration(0); i < shutdownTimeout; i += time.Second {
|
|
|
|
if !system.IsProcessAlive(r.daemonPid) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
if system.IsProcessAlive(r.daemonPid) {
|
|
|
|
r.logger.WithField("pid", r.daemonPid).Warn("daemon didn't stop within 15 secs, killing it")
|
|
|
|
syscall.Kill(r.daemonPid, syscall.SIGKILL)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 15:15:21 -04:00
|
|
|
func (r *remote) killDaemon() {
|
|
|
|
// Try to get a stack trace
|
|
|
|
syscall.Kill(r.daemonPid, syscall.SIGUSR1)
|
|
|
|
<-time.After(100 * time.Millisecond)
|
|
|
|
system.KillProcess(r.daemonPid)
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
func (r *remote) platformCleanup() {
|
|
|
|
os.Remove(filepath.Join(r.stateDir, sockFile))
|
|
|
|
}
|