1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use daemon exec root for swarm control socket

Right now docker puts swarm's control socket into the docker root dir
(e.g. /var/lib/docker).
This can cause some nasty issues with path length being > 108
characters, especially in our CI environment.

Since we already have some other state going in the daemon's exec root
(libcontainerd and libnetwork), I think it makes sense to move the
control socket to this location, especially since there are other unix
sockets being created here by docker so it must always be at a path that
works.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-08-19 16:06:28 -04:00
parent bf61c916ee
commit 4d95ea319c
6 changed files with 34 additions and 2 deletions

View file

@ -275,6 +275,7 @@ func (cli *DaemonCli) start() (err error) {
Backend: d,
NetworkSubnetsProvider: d,
DefaultAdvertiseAddr: cli.Config.SwarmDefaultAdvertiseAddr,
RuntimeRoot: cli.getSwarmRunRoot(),
})
if err != nil {
logrus.Fatalf("Error creating cluster component: %v", err)

View file

@ -61,6 +61,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
}
// 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")
}
func allocateDaemonPort(addr string) error {
return nil
}

View file

@ -85,6 +85,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
}
// 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")
}
// allocateDaemonPort ensures that there are no containers
// that try to use any port allocated for the docker server.
func allocateDaemonPort(addr string) error {

View file

@ -73,6 +73,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
return ""
}
// getSwarmRunRoot gets the root directory for swarm to store runtime state
// For example, the control socket
func (cli *DaemonCli) getSwarmRunRoot() string {
return ""
}
func allocateDaemonPort(addr string) error {
return nil
}

View file

@ -103,6 +103,9 @@ type Config struct {
// DefaultAdvertiseAddr is the default host/IP or network interface to use
// if no AdvertiseAddr value is specified.
DefaultAdvertiseAddr string
// path to store runtime state, such as the swarm control socket
RuntimeRoot string
}
// Cluster provides capabilities to participate in a cluster as a worker or a
@ -111,6 +114,7 @@ type Cluster struct {
sync.RWMutex
*node
root string
runtimeRoot string
config Config
configEvent chan struct{} // todo: make this array and goroutine safe
localAddr string
@ -138,10 +142,17 @@ func New(config Config) (*Cluster, error) {
if err := os.MkdirAll(root, 0700); err != nil {
return nil, err
}
if config.RuntimeRoot == "" {
config.RuntimeRoot = root
}
if err := os.MkdirAll(config.RuntimeRoot, 0700); err != nil {
return nil, err
}
c := &Cluster{
root: root,
config: config,
configEvent: make(chan struct{}, 10),
runtimeRoot: config.RuntimeRoot,
}
st, err := c.loadState()
@ -275,7 +286,7 @@ func (c *Cluster) startNewNode(forceNewCluster bool, localAddr, remoteAddr, list
n, err := swarmagent.NewNode(&swarmagent.NodeConfig{
Hostname: c.config.Name,
ForceNewCluster: forceNewCluster,
ListenControlAPI: filepath.Join(c.root, controlSocket),
ListenControlAPI: filepath.Join(c.runtimeRoot, controlSocket),
ListenRemoteAPI: listenAddr,
AdvertiseRemoteAPI: advertiseAddr,
JoinAddr: joinAddr,

View file

@ -41,6 +41,7 @@ type Daemon struct {
userlandProxy bool
useDefaultHost bool
useDefaultTLSHost bool
execRoot string
}
type clientConfig struct {
@ -81,6 +82,7 @@ func NewDaemon(c *check.C) *Daemon {
root: daemonRoot,
storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
userlandProxy: userlandProxy,
execRoot: filepath.Join(os.TempDir(), "docker-execroot", id),
}
}
@ -145,7 +147,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
args := append(d.GlobalFlags,
"--containerd", "/var/run/docker/libcontainerd/docker-containerd.sock",
"--graph", d.root,
"--exec-root", filepath.Join(d.folder, "exec-root"),
"--exec-root", d.execRoot,
"--pidfile", fmt.Sprintf("%s/docker.pid", d.folder),
fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
)