Skip to content

Commit

Permalink
Switch default logdriver and eventslogger to journald, if root
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jun 30, 2021
1 parent b1f7d65 commit 008f852
Show file tree
Hide file tree
Showing 10 changed files with 1,640 additions and 14 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GO_BUILD=$(GO) build
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
endif
BUILDTAGS := containers_image_openpgp,systemd
BUILDTAGS := containers_image_openpgp,systemd,exclude_graphdriver_devicemapper
DESTDIR ?=
PREFIX := /usr/local
CONFIGDIR := ${PREFIX}/share/containers
Expand Down Expand Up @@ -35,8 +35,17 @@ define go-build
GOOS=$(1) GOARCH=$(2) $(GO) build -tags "$(3)" ./...
endef

define go-build-c
CGO_ENABLED=1 \
GOOS=$(1) GOARCH=$(2) $(GO) build -tags "$(3)" ./...
endef

.PHONY:
build-cross:
$(call go-build-c,linux) # attempt to build without tags
$(call go-build-c,linux,,${BUILDTAGS})
$(call go-build-c,linux,386,${BUILDTAGS})
$(call go-build,linux) # attempt to build without tags
$(call go-build,linux,386,${BUILDTAGS})
$(call go-build,linux,arm,${BUILDTAGS})
$(call go-build,linux,arm64,${BUILDTAGS})
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/containers/image/v5 v5.13.2
github.com/containers/ocicrypt v1.1.2
github.com/containers/storage v1.32.5
github.com/coreos/go-systemd/v22 v22.3.2
github.com/disiqueira/gotree/v3 v3.0.2
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v20.10.7+incompatible
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ const (
DefaultApparmorProfile = apparmor.Profile
// SystemdCgroupsManager represents systemd native cgroup manager
SystemdCgroupsManager = "systemd"
// DefaultLogDriver is the default type of log files
DefaultLogDriver = "k8s-file"
// DefaultLogSizeMax is the default value for the maximum log size
// allowed for a container. Negative values mean that no limit is imposed.
DefaultLogSizeMax = -1
Expand Down
7 changes: 6 additions & 1 deletion pkg/config/nosystemd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// +build !systemd
// +build !systemd !cgo

package config

const (
// DefaultLogDriver is the default type of log files
DefaultLogDriver = "k8s-file"
)

func defaultCgroupManager() string {
return CgroupfsCgroupsManager
}
Expand Down
41 changes: 31 additions & 10 deletions pkg/config/systemd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build systemd
// +build systemd,cgo

package config

Expand All @@ -9,11 +9,19 @@ import (

"github.com/containers/common/pkg/cgroupv2"
"github.com/containers/storage/pkg/unshare"
"github.com/coreos/go-systemd/v22/sdjournal"
)

var (
systemdOnce sync.Once
usesSystemd bool
systemdOnce sync.Once
usesSystemd bool
journaldOnce sync.Once
usesJournald bool
)

const (
// DefaultLogDriver is the default type of log files
DefaultLogDriver = "journald"
)

func defaultCgroupManager() string {
Expand All @@ -29,20 +37,17 @@ func defaultCgroupManager() string {
}

func defaultEventsLogger() string {
if useSystemd() {
if useJournald() {
return "journald"
}
return "file"
}

func defaultLogDriver() string {
// If we decide to change the default for logdriver, it should be done here.
if useSystemd() {
return DefaultLogDriver
if useJournald() {
return "journald"
}

return DefaultLogDriver

return "k8s-file"
}

func useSystemd() bool {
Expand All @@ -56,3 +61,19 @@ func useSystemd() bool {
})
return usesSystemd
}

func useJournald() bool {
journaldOnce.Do(func() {
if !useSystemd() {
return
}
journal, err := sdjournal.NewJournal()
if err != nil {
return
}
journal.Close()
usesJournald = true
return
})
return usesJournald
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 008f852

Please sign in to comment.