2016-03-26 02:38:00 +03:00
|
|
|
// +build !windows,!solaris
|
2015-05-16 02:34:26 +03:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-15 16:36:19 +03:00
|
|
|
"fmt"
|
2016-04-09 09:49:33 +03:00
|
|
|
"net"
|
2015-05-16 02:34:26 +03:00
|
|
|
"os"
|
2015-12-11 02:35:10 +03:00
|
|
|
"os/signal"
|
2016-03-24 21:42:03 +03:00
|
|
|
"path/filepath"
|
2016-04-09 09:49:33 +03:00
|
|
|
"strconv"
|
2015-06-15 16:36:19 +03:00
|
|
|
"syscall"
|
2015-05-16 02:34:26 +03:00
|
|
|
|
2016-04-12 18:21:20 +03:00
|
|
|
"github.com/docker/docker/cmd/dockerd/hack"
|
2015-05-16 02:34:26 +03:00
|
|
|
"github.com/docker/docker/daemon"
|
2016-03-18 21:50:19 +03:00
|
|
|
"github.com/docker/docker/libcontainerd"
|
2016-04-09 09:49:33 +03:00
|
|
|
"github.com/docker/libnetwork/portallocator"
|
2015-05-16 02:34:26 +03:00
|
|
|
)
|
|
|
|
|
2015-12-11 02:35:10 +03:00
|
|
|
const defaultDaemonConfigFile = "/etc/docker/daemon.json"
|
|
|
|
|
2015-06-15 16:36:19 +03:00
|
|
|
// setDefaultUmask sets the umask to 0022 to avoid problems
|
|
|
|
// caused by custom umask
|
|
|
|
func setDefaultUmask() error {
|
|
|
|
desiredUmask := 0022
|
|
|
|
syscall.Umask(desiredUmask)
|
|
|
|
if umask := syscall.Umask(desiredUmask); umask != desiredUmask {
|
|
|
|
return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-07-30 22:39:19 +03:00
|
|
|
|
2016-11-04 22:42:21 +03:00
|
|
|
func getDaemonConfDir(_ string) string {
|
2015-07-30 22:39:19 +03:00
|
|
|
return "/etc/docker"
|
|
|
|
}
|
2015-12-11 02:35:10 +03:00
|
|
|
|
|
|
|
// setupConfigReloadTrap configures the USR2 signal to reload the configuration.
|
2016-04-23 03:16:14 +03:00
|
|
|
func (cli *DaemonCli) setupConfigReloadTrap() {
|
2015-12-11 02:35:10 +03:00
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, syscall.SIGHUP)
|
|
|
|
go func() {
|
|
|
|
for range c {
|
2016-04-23 03:16:14 +03:00
|
|
|
cli.reloadConfig()
|
2015-12-11 02:35:10 +03:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2016-03-18 21:50:19 +03:00
|
|
|
|
|
|
|
func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
|
|
|
|
opts := []libcontainerd.RemoteOption{
|
|
|
|
libcontainerd.WithDebugLog(cli.Config.Debug),
|
2016-07-12 01:26:23 +03:00
|
|
|
libcontainerd.WithOOMScore(cli.Config.OOMScoreAdjust),
|
2016-03-18 21:50:19 +03:00
|
|
|
}
|
|
|
|
if cli.Config.ContainerdAddr != "" {
|
|
|
|
opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
|
|
|
|
} else {
|
|
|
|
opts = append(opts, libcontainerd.WithStartDaemon(true))
|
|
|
|
}
|
2016-03-24 19:18:03 +03:00
|
|
|
if daemon.UsingSystemd(cli.Config) {
|
|
|
|
args := []string{"--systemd-cgroup=true"}
|
|
|
|
opts = append(opts, libcontainerd.WithRuntimeArgs(args))
|
|
|
|
}
|
2016-07-27 18:30:15 +03:00
|
|
|
if cli.Config.LiveRestoreEnabled {
|
2016-06-02 21:10:55 +03:00
|
|
|
opts = append(opts, libcontainerd.WithLiveRestore(true))
|
|
|
|
}
|
2016-05-24 00:49:50 +03:00
|
|
|
opts = append(opts, libcontainerd.WithRuntimePath(daemon.DefaultRuntimeBinary))
|
2016-03-18 21:50:19 +03:00
|
|
|
return opts
|
|
|
|
}
|
2016-03-24 21:42:03 +03:00
|
|
|
|
|
|
|
// getLibcontainerdRoot gets the root directory for libcontainerd/containerd to
|
|
|
|
// store their state.
|
|
|
|
func (cli *DaemonCli) getLibcontainerdRoot() string {
|
|
|
|
return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
|
|
|
|
}
|
2016-04-09 09:49:33 +03:00
|
|
|
|
2016-08-19 23:06:28 +03:00
|
|
|
// getSwarmRunRoot gets the root directory for swarm to store runtime state
|
|
|
|
// For example, the control socket
|
|
|
|
func (cli *DaemonCli) getSwarmRunRoot() string {
|
|
|
|
return filepath.Join(cli.Config.ExecRoot, "swarm")
|
|
|
|
}
|
|
|
|
|
2016-04-09 09:49:33 +03:00
|
|
|
// allocateDaemonPort ensures that there are no containers
|
|
|
|
// that try to use any port allocated for the docker server.
|
|
|
|
func allocateDaemonPort(addr string) error {
|
|
|
|
host, port, err := net.SplitHostPort(addr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
intPort, err := strconv.Atoi(port)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var hostIPs []net.IP
|
|
|
|
if parsedIP := net.ParseIP(host); parsedIP != nil {
|
|
|
|
hostIPs = append(hostIPs, parsedIP)
|
|
|
|
} else if hostIPs, err = net.LookupIP(host); err != nil {
|
|
|
|
return fmt.Errorf("failed to lookup %s address in host specification", host)
|
|
|
|
}
|
|
|
|
|
|
|
|
pa := portallocator.Get()
|
|
|
|
for _, hostIP := range hostIPs {
|
|
|
|
if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
|
|
|
return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-04-23 03:16:14 +03:00
|
|
|
|
|
|
|
// notifyShutdown is called after the daemon shuts down but before the process exits.
|
|
|
|
func notifyShutdown(err error) {
|
|
|
|
}
|
2016-04-12 18:21:20 +03:00
|
|
|
|
|
|
|
func wrapListeners(proto string, ls []net.Listener) []net.Listener {
|
2016-05-22 06:40:15 +03:00
|
|
|
switch proto {
|
|
|
|
case "unix":
|
|
|
|
ls[0] = &hack.MalformedHostHeaderOverride{ls[0]}
|
|
|
|
case "fd":
|
|
|
|
for i := range ls {
|
|
|
|
ls[i] = &hack.MalformedHostHeaderOverride{ls[i]}
|
2016-04-12 18:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ls
|
|
|
|
}
|