Skip to content

Commit

Permalink
cmd: dockerd: make systemd specific cgroups tweaks build-time optional
Browse files Browse the repository at this point in the history
When running under systemd, we have to do some tweaks for systemd's
non standard cgroups setups. This isn't required if we'll never be running
in such an environment (eg. there're many distros free of such Lennartisms).

Therefore make it possible to opt out at build time by settings the
'no_systemd' tag.

changes v2: fixed danling import
            renamed 'nosystemd' tag to 'no_systemd'
            dropped old build tags

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
  • Loading branch information
metux committed Aug 25, 2023
1 parent 3e5b2a6 commit dea1879
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
15 changes: 15 additions & 0 deletions cmd/dockerd/daemon_nosystemd_unix.go
@@ -0,0 +1,15 @@
//go:build no_systemd

package main

import (
"github.com/docker/docker/daemon/config"
)

func newCgroupParent(config *config.Config) string {
if config.CgroupParent = "" {
return "docker"
} else {
return config.CgroupParent
}
}
23 changes: 23 additions & 0 deletions cmd/dockerd/daemon_systemd_unix.go
@@ -0,0 +1,23 @@
//go:build linux && !no_systemd

package main

import (
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/config"
)

func newCgroupParent(config *config.Config) string {
cgroupParent := "docker"
useSystemd := daemon.UsingSystemd(config)
if useSystemd {
cgroupParent = "system.slice"
}
if config.CgroupParent != "" {
cgroupParent = config.CgroupParent
}
if useSystemd {
cgroupParent = cgroupParent + ":" + "docker" + ":"
}
return cgroupParent
}
17 changes: 0 additions & 17 deletions cmd/dockerd/daemon_unix.go
Expand Up @@ -12,8 +12,6 @@ import (
"time"

"github.com/containerd/containerd/log"
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/libcontainerd/supervisor"
"github.com/docker/docker/libnetwork/portallocator"
"github.com/docker/docker/pkg/homedir"
Expand Down Expand Up @@ -101,21 +99,6 @@ func allocateDaemonPort(addr string) error {
return nil
}

func newCgroupParent(config *config.Config) string {
cgroupParent := "docker"
useSystemd := daemon.UsingSystemd(config)
if useSystemd {
cgroupParent = "system.slice"
}
if config.CgroupParent != "" {
cgroupParent = config.CgroupParent
}
if useSystemd {
cgroupParent = cgroupParent + ":" + "docker" + ":"
}
return cgroupParent
}

func (cli *DaemonCli) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
if cli.ContainerdAddr != "" {
// use system containerd at the given address.
Expand Down

0 comments on commit dea1879

Please sign in to comment.