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'

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
  • Loading branch information
metux committed Jun 14, 2021
1 parent 5e62ca1 commit 14bc234
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
15 changes: 15 additions & 0 deletions cmd/dockerd/daemon_nosystemd_unix.go
@@ -0,0 +1,15 @@
// +build no_systemd

package main

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

func newCgroupParent(config *config.Config) string {
cgroupParent := "docker"
if config.CgroupParent != "" {
cgroupParent = config.CgroupParent
}
return cgroupParent
}
23 changes: 23 additions & 0 deletions cmd/dockerd/daemon_systemd_unix.go
@@ -0,0 +1,23 @@
// +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
}
16 changes: 0 additions & 16 deletions cmd/dockerd/daemon_unix.go
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/containerd/containerd/runtime/v1/linux"
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/libcontainerd/supervisor"
"github.com/docker/docker/libnetwork/portallocator"
Expand Down Expand Up @@ -121,21 +120,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) {
var waitForShutdown func(time.Duration) error
if cli.Config.ContainerdAddr == "" {
Expand Down

0 comments on commit 14bc234

Please sign in to comment.