diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f6f6e7aba..e482b03e8 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -191,7 +191,6 @@ var _ = Describe("Config", func() { gomega.Expect(defaultConfig.GetDefaultEnvEx(false, true)).To(gomega.BeEquivalentTo(httpEnvs)) gomega.Expect(strings.Join(defaultConfig.GetDefaultEnvEx(true, true), ",")).To(gomega.ContainSubstring("HTTP_PROXY")) gomega.Expect(strings.Join(defaultConfig.GetDefaultEnvEx(true, true), ",")).To(gomega.ContainSubstring("foo")) - // Undo that if proxyEnvSet { os.Setenv("HTTP_PROXY", oldProxy) @@ -292,7 +291,16 @@ var _ = Describe("Config", func() { gomega.Expect(config.Network.CNIPluginDirs).To(gomega.Equal(pluginDirs)) gomega.Expect(config.Engine.NumLocks).To(gomega.BeEquivalentTo(2048)) gomega.Expect(config.Engine.OCIRuntimes["runc"]).To(gomega.Equal(OCIRuntimeMap["runc"])) - gomega.Expect(config.LogDriver()).To(gomega.Equal("k8s-file")) + if useSystemd() { + gomega.Expect(config.Engine.CgroupManager).To(gomega.BeEquivalentTo("systemd")) + gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("journald")) + gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file")) + } else { + gomega.Expect(config.Engine.CgroupManager).To(gomega.BeEquivalentTo("cgroupfs")) + gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("file")) + gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file")) + } + }) It("should success with valid user file path", func() { diff --git a/pkg/config/default.go b/pkg/config/default.go index 2b660d1ab..d5a7d5b84 100644 --- a/pkg/config/default.go +++ b/pkg/config/default.go @@ -195,7 +195,7 @@ func DefaultConfig() (*Config, error) { Init: false, InitPath: "", IPCNS: "private", - LogDriver: DefaultLogDriver, + LogDriver: defaultLogDriver(), LogSizeMax: DefaultLogSizeMax, NetNS: netns, NoHosts: false, diff --git a/pkg/config/nosystemd.go b/pkg/config/nosystemd.go index 5b82b1389..6e39a6ccd 100644 --- a/pkg/config/nosystemd.go +++ b/pkg/config/nosystemd.go @@ -3,9 +3,17 @@ package config func defaultCgroupManager() string { - return "cgroupfs" + return CgroupfsCgroupsManager } func defaultEventsLogger() string { return "file" } + +func defaultLogDriver() string { + return DefaultLogDriver +} + +func useSystemd() bool { + return false +} diff --git a/pkg/config/systemd.go b/pkg/config/systemd.go index 02e5c4ac2..fe2be8e2b 100644 --- a/pkg/config/systemd.go +++ b/pkg/config/systemd.go @@ -3,11 +3,21 @@ package config import ( + "sync" + "github.com/containers/common/pkg/cgroupv2" "github.com/containers/storage/pkg/unshare" ) +var ( + systemdOnce sync.Once + usesSystemd bool +) + func defaultCgroupManager() string { + if !useSystemd() { + return CgroupfsCgroupsManager + } enabled, err := cgroupv2.Enabled() if err == nil && !enabled && unshare.IsRootless() { return CgroupfsCgroupsManager @@ -16,5 +26,30 @@ func defaultCgroupManager() string { return SystemdCgroupsManager } func defaultEventsLogger() string { - return "journald" + if useSystemd() { + 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 + } + + return DefaultLogDriver + +} + +func useSystemd() bool { + systemdOnce.Do(func() { + dat, err := ioutil.ReadFile("/proc/1/comm") + if err == nil { + val := strings.TrimSuffix(string(dat), "\n") + usesSystemd = (val == "systemd") + } + return + }) + return usesSystemd }