Skip to content

Commit

Permalink
Use systemd drop-in for the docker-machine configuration
Browse files Browse the repository at this point in the history
Using systemd drop-in for the configuration is better for inherit the
package default settings, without the need of sync the settings
between 2 projects.

Fixes docker#3963

Signed-off-by: Tao Wang <twang2218@gmail.com>
  • Loading branch information
twang2218 committed Jan 25, 2017
1 parent 7b7a141 commit b6e85bf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
15 changes: 2 additions & 13 deletions libmachine/provision/coreos.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,11 @@ func (provisioner *CoreOSProvisioner) GenerateDockerOptions(dockerPort int) (*Do
arg = ""
}

engineConfigTmpl := `[Unit]
Description=Docker Socket for the API
After=docker.socket early-docker.target network.target
Requires=docker.socket early-docker.target
[Service]
engineConfigTmpl := `[Service]
Environment=TMPDIR=/var/tmp
EnvironmentFile=-/run/flannel_docker_opts.env
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
ExecStart=
ExecStart=/usr/lib/coreos/dockerd ` + arg + ` --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:{{.DockerPort}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}}{{ range .EngineOptions.Labels }} --label {{.}}{{ end }}{{ range .EngineOptions.InsecureRegistry }} --insecure-registry {{.}}{{ end }}{{ range .EngineOptions.RegistryMirror }} --registry-mirror {{.}}{{ end }}{{ range .EngineOptions.ArbitraryFlags }} --{{.}}{{ end }} \$DOCKER_OPTS \$DOCKER_OPT_BIP \$DOCKER_OPT_MTU \$DOCKER_OPT_IPMASQ
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
[Install]
WantedBy=multi-user.target
`

t, err := template.New("engineConfig").Parse(engineConfigTmpl)
Expand Down
19 changes: 2 additions & 17 deletions libmachine/provision/redhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,10 @@ priority=1
enabled=1
gpgkey=https://yum.dockerproject.org/gpg
`
engineConfigTemplate = `[Unit]
Description=Docker Application Container Engine
After=network.target
[Service]
Type=notify
engineConfigTemplate = `[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:{{.DockerPort}} -H unix:///var/run/docker.sock --storage-driver {{.EngineOptions.StorageDriver}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}} {{ range .EngineOptions.Labels }}--label {{.}} {{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} {{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} {{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} {{ end }}
ExecReload=/bin/kill -s HUP $MAINPID
MountFlags=slave
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
[Install]
WantedBy=multi-user.target
`

majorVersionRE = regexp.MustCompile(`^(\d+)(\..*)?`)
Expand Down
10 changes: 2 additions & 8 deletions libmachine/provision/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewSystemdProvisioner(osReleaseID string, d drivers.Driver) SystemdProvisio
GenericProvisioner{
SSHCommander: GenericSSHCommander{Driver: d},
DockerOptionsDir: "/etc/docker",
DaemonOptionsFile: "/etc/systemd/system/docker.service",
DaemonOptionsFile: "/etc/systemd/system/docker.service.d/10-machine.conf",
OsReleaseID: osReleaseID,
Packages: []string{
"curl",
Expand All @@ -41,15 +41,9 @@ func (p *SystemdProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptio
p.EngineOptions.Labels = append(p.EngineOptions.Labels, driverNameLabel)

engineConfigTmpl := `[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:{{.DockerPort}} -H unix:///var/run/docker.sock --storage-driver {{.EngineOptions.StorageDriver}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}} {{ range .EngineOptions.Labels }}--label {{.}} {{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} {{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} {{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} {{ end }}
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
[Install]
WantedBy=multi-user.target
`
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion libmachine/provision/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func ConfigureAuth(p Provisioner) error {

log.Info("Setting Docker configuration on the remote daemon...")

if _, err = p.SSHCommand(fmt.Sprintf("printf %%s \"%s\" | sudo tee %s", dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath)); err != nil {
if _, err = p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | sudo tee %s", path.Dir(dkrcfg.EngineOptionsPath), dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath)); err != nil {
return err
}

Expand Down

0 comments on commit b6e85bf

Please sign in to comment.