Esempio n. 1
0
func createRktGarbageService(fsc *fs.FsClient, useOverlay bool) error {
	opts := rktOptions{
		UseOverlay: useOverlay,
	}

	b, err := templates.Render(rktGarbageServiceTemplate, opts)
	if err != nil {
		return maskAny(err)
	}

	if err := fsc.Write(rktSystemdPath+rktGarbageServiceName, b.Bytes(), unitFileMode); err != nil {
		return maskAny(err)
	}

	rktGarbageTimer, err := templates.Asset(rktGarbageTimerTemplate)
	if err != nil {
		return maskAny(err)
	}

	if err := fsc.Write(rktSystemdPath+rktGarbageTimerName, rktGarbageTimer, unitFileMode); err != nil {
		return maskAny(err)
	}

	return nil
}
Esempio n. 2
0
func setupService(fsc *fs.FsClient) error {
	iptablesService, err := templates.Asset(serviceTemplate)
	if err != nil {
		return maskAny(err)
	}

	if err := fsc.Write(servicePath, iptablesService, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}
Esempio n. 3
0
func setupNetfilter(fsc *fs.FsClient) error {
	netfilterService, err := templates.Asset(netfilterTemplate)
	if err != nil {
		return maskAny(err)
	}

	if err := fsc.Write(netfilterPath, netfilterService, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}
Esempio n. 4
0
func Setup(fsc *fs.FsClient, sc *systemd.SystemdClient, fc fetchclient.FetchClient, distributionPath, dockerVersion string, privateRegistry []string, useIPTables, restartDaemon bool, useOverlay bool) error {
	vLogger("\n# call docker.Setup()")

	// This is the version where Docker split into multiple binaries.
	dockerMultipleBinariesVersion, _ := semver.NewVersion("1.11.0")

	semverDockerVersion, err := semver.NewVersion(dockerVersion)
	if err != nil {
		return maskAny(err)
	}

	dockerBinariesToGetAndWrite := []string{}
	if semverDockerVersion.LessThan(*dockerMultipleBinariesVersion) {
		dockerBinariesToGetAndWrite = []string{"docker"}
	} else {
		dockerBinariesToGetAndWrite = []string{
			"docker",
			"docker-containerd",
			"docker-containerd-ctr",
			"docker-containerd-shim",
			"docker-runc",
		}
	}

	for _, dockerBinaryName := range dockerBinariesToGetAndWrite {
		dockerRaw, err := fc.Get("docker/" + dockerVersion + "/" + dockerBinaryName)
		if err != nil {
			return maskAny(err)
		}

		if err := fsc.Write(distributionPath+"/"+dockerBinaryName, dockerRaw, fileMode); err != nil {
			return maskAny(err)
		}
	}

	err = createDockerService(fsc, dockerVersion, privateRegistry, useIPTables, useOverlay)
	if err != nil {
		return maskAny(err)
	}

	dockerTcpSocket, err := templates.Asset(socketTemplate)
	if err != nil {
		return maskAny(err)
	}

	// write docker-tcp.socket unit to host
	if err := fsc.Write(socketPath, dockerTcpSocket, fileMode); err != nil {
		return maskAny(err)
	}

	// reload unit files, that is, `systemctl daemon-reload`
	if err := sc.Reload(); err != nil {
		return maskAny(err)
	}

	if restartDaemon {
		// start docker-tcp.socket unit
		if err := sc.Start(socketName); err != nil {
			return maskAny(err)
		}

		// start docker.service unit
		if err := sc.Start(serviceName); err != nil {
			// If there is a dependency error, we just log it. This only happens in case
			// the provisioner is restarted. Then systemd throws an error when starting
			// docker, even though the only dependency (docker-tcp.socket) does not
			// fail.
			if systemd.IsJobDependency(err) {
				vLogger(err.Error())
			} else {
				return maskAny(err)
			}
		}
	}

	return nil
}