diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 957e3e0e1..812e1c930 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -336,10 +336,13 @@ image_copy_tmp_dir="storage"` gomega.Expect(config.Engine.OCIRuntimes["runc"]).To(gomega.Equal(OCIRuntimeMap["runc"])) 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")) + } + if useJournald() { + gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("journald")) + gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("journald")) + } else { gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("file")) gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file")) } diff --git a/pkg/config/nosystemd.go b/pkg/config/nosystemd.go index 2a3b6fb35..f64b2dfc6 100644 --- a/pkg/config/nosystemd.go +++ b/pkg/config/nosystemd.go @@ -22,3 +22,7 @@ func defaultLogDriver() string { func useSystemd() bool { return false } + +func useJournald() bool { + return false +} diff --git a/pkg/config/systemd.go b/pkg/config/systemd.go index fab3ea437..186e8b343 100644 --- a/pkg/config/systemd.go +++ b/pkg/config/systemd.go @@ -4,12 +4,12 @@ package config import ( "io/ioutil" + "path/filepath" "strings" "sync" "github.com/containers/common/pkg/cgroupv2" "github.com/containers/storage/pkg/unshare" - "github.com/coreos/go-systemd/v22/sdjournal" ) var ( @@ -67,12 +67,20 @@ func useJournald() bool { if !useSystemd() { return } - journal, err := sdjournal.NewJournal() - if err != nil { - return + for _, root := range []string{"/run/log/journal", "/var/log/journal"} { + dirs, err := ioutil.ReadDir(root) + if err != nil { + continue + } + for _, d := range dirs { + if d.IsDir() { + if _, err := ioutil.ReadDir(filepath.Join(root, d.Name())); err == nil { + usesJournald = true + return + } + } + } } - journal.Close() - usesJournald = true return }) return usesJournald