Use daemon exec root for swarm control socket
| ... | ... |
@@ -256,6 +256,7 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
|
| 256 | 256 |
Backend: d, |
| 257 | 257 |
NetworkSubnetsProvider: d, |
| 258 | 258 |
DefaultAdvertiseAddr: cli.Config.SwarmDefaultAdvertiseAddr, |
| 259 |
+ RuntimeRoot: cli.getSwarmRunRoot(), |
|
| 259 | 260 |
}) |
| 260 | 261 |
if err != nil {
|
| 261 | 262 |
logrus.Fatalf("Error creating cluster component: %v", err)
|
| ... | ... |
@@ -61,6 +61,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
|
| 61 | 61 |
return filepath.Join(cli.Config.ExecRoot, "libcontainerd") |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 |
+// getSwarmRunRoot gets the root directory for swarm to store runtime state |
|
| 65 |
+// For example, the control socket |
|
| 66 |
+func (cli *DaemonCli) getSwarmRunRoot() string {
|
|
| 67 |
+ return filepath.Join(cli.Config.ExecRoot, "swarm") |
|
| 68 |
+} |
|
| 69 |
+ |
|
| 64 | 70 |
func allocateDaemonPort(addr string) error {
|
| 65 | 71 |
return nil |
| 66 | 72 |
} |
| ... | ... |
@@ -85,6 +85,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
|
| 85 | 85 |
return filepath.Join(cli.Config.ExecRoot, "libcontainerd") |
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 |
+// getSwarmRunRoot gets the root directory for swarm to store runtime state |
|
| 89 |
+// For example, the control socket |
|
| 90 |
+func (cli *DaemonCli) getSwarmRunRoot() string {
|
|
| 91 |
+ return filepath.Join(cli.Config.ExecRoot, "swarm") |
|
| 92 |
+} |
|
| 93 |
+ |
|
| 88 | 94 |
// allocateDaemonPort ensures that there are no containers |
| 89 | 95 |
// that try to use any port allocated for the docker server. |
| 90 | 96 |
func allocateDaemonPort(addr string) error {
|
| ... | ... |
@@ -73,6 +73,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
|
| 73 | 73 |
return "" |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 |
+// getSwarmRunRoot gets the root directory for swarm to store runtime state |
|
| 77 |
+// For example, the control socket |
|
| 78 |
+func (cli *DaemonCli) getSwarmRunRoot() string {
|
|
| 79 |
+ return "" |
|
| 80 |
+} |
|
| 81 |
+ |
|
| 76 | 82 |
func allocateDaemonPort(addr string) error {
|
| 77 | 83 |
return nil |
| 78 | 84 |
} |
| ... | ... |
@@ -103,6 +103,9 @@ type Config struct {
|
| 103 | 103 |
// DefaultAdvertiseAddr is the default host/IP or network interface to use |
| 104 | 104 |
// if no AdvertiseAddr value is specified. |
| 105 | 105 |
DefaultAdvertiseAddr string |
| 106 |
+ |
|
| 107 |
+ // path to store runtime state, such as the swarm control socket |
|
| 108 |
+ RuntimeRoot string |
|
| 106 | 109 |
} |
| 107 | 110 |
|
| 108 | 111 |
// Cluster provides capabilities to participate in a cluster as a worker or a |
| ... | ... |
@@ -111,6 +114,7 @@ type Cluster struct {
|
| 111 | 111 |
sync.RWMutex |
| 112 | 112 |
*node |
| 113 | 113 |
root string |
| 114 |
+ runtimeRoot string |
|
| 114 | 115 |
config Config |
| 115 | 116 |
configEvent chan struct{} // todo: make this array and goroutine safe
|
| 116 | 117 |
localAddr string |
| ... | ... |
@@ -138,10 +142,17 @@ func New(config Config) (*Cluster, error) {
|
| 138 | 138 |
if err := os.MkdirAll(root, 0700); err != nil {
|
| 139 | 139 |
return nil, err |
| 140 | 140 |
} |
| 141 |
+ if config.RuntimeRoot == "" {
|
|
| 142 |
+ config.RuntimeRoot = root |
|
| 143 |
+ } |
|
| 144 |
+ if err := os.MkdirAll(config.RuntimeRoot, 0700); err != nil {
|
|
| 145 |
+ return nil, err |
|
| 146 |
+ } |
|
| 141 | 147 |
c := &Cluster{
|
| 142 | 148 |
root: root, |
| 143 | 149 |
config: config, |
| 144 | 150 |
configEvent: make(chan struct{}, 10),
|
| 151 |
+ runtimeRoot: config.RuntimeRoot, |
|
| 145 | 152 |
} |
| 146 | 153 |
|
| 147 | 154 |
st, err := c.loadState() |
| ... | ... |
@@ -275,7 +286,7 @@ func (c *Cluster) startNewNode(forceNewCluster bool, localAddr, remoteAddr, list |
| 275 | 275 |
n, err := swarmagent.NewNode(&swarmagent.NodeConfig{
|
| 276 | 276 |
Hostname: c.config.Name, |
| 277 | 277 |
ForceNewCluster: forceNewCluster, |
| 278 |
- ListenControlAPI: filepath.Join(c.root, controlSocket), |
|
| 278 |
+ ListenControlAPI: filepath.Join(c.runtimeRoot, controlSocket), |
|
| 279 | 279 |
ListenRemoteAPI: listenAddr, |
| 280 | 280 |
AdvertiseRemoteAPI: advertiseAddr, |
| 281 | 281 |
JoinAddr: joinAddr, |
| ... | ... |
@@ -42,6 +42,7 @@ type Daemon struct {
|
| 42 | 42 |
userlandProxy bool |
| 43 | 43 |
useDefaultHost bool |
| 44 | 44 |
useDefaultTLSHost bool |
| 45 |
+ execRoot string |
|
| 45 | 46 |
} |
| 46 | 47 |
|
| 47 | 48 |
type clientConfig struct {
|
| ... | ... |
@@ -82,6 +83,7 @@ func NewDaemon(c *check.C) *Daemon {
|
| 82 | 82 |
root: daemonRoot, |
| 83 | 83 |
storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
|
| 84 | 84 |
userlandProxy: userlandProxy, |
| 85 |
+ execRoot: filepath.Join(os.TempDir(), "docker-execroot", id), |
|
| 85 | 86 |
} |
| 86 | 87 |
} |
| 87 | 88 |
|
| ... | ... |
@@ -146,7 +148,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
| 146 | 146 |
args := append(d.GlobalFlags, |
| 147 | 147 |
"--containerd", "/var/run/docker/libcontainerd/docker-containerd.sock", |
| 148 | 148 |
"--graph", d.root, |
| 149 |
- "--exec-root", filepath.Join(d.folder, "exec-root"), |
|
| 149 |
+ "--exec-root", d.execRoot, |
|
| 150 | 150 |
"--pidfile", fmt.Sprintf("%s/docker.pid", d.folder),
|
| 151 | 151 |
fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
|
| 152 | 152 |
) |