From 67e7590170680969b05e480e81ec58d84a19343c Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 4 Jun 2025 11:19:27 +0200 Subject: [PATCH] Fix journald mount on non systemd systems (#800) --- pkg/utils/chroot.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/utils/chroot.go b/pkg/utils/chroot.go index 0c88f63..aa1649c 100644 --- a/pkg/utils/chroot.go +++ b/pkg/utils/chroot.go @@ -38,13 +38,20 @@ type Chroot struct { } func NewChroot(path string, config *agentConfig.Config) *Chroot { - return &Chroot{ + chroot := &Chroot{ path: path, - defaultMounts: []string{"/dev", "/dev/pts", "/proc", "/sys", "/run/systemd/journal/"}, // Add journal so we keep logs + defaultMounts: []string{"/dev", "/dev/pts", "/proc", "/sys"}, extraMounts: map[string]string{}, activeMounts: []string{}, config: config, } + + // If we have systemd running, we need to mount the journal directory to keep logger open + if fi, err := os.Lstat("/run/systemd/system"); err == nil && fi.IsDir() { + chroot.defaultMounts = append(chroot.defaultMounts, "/run/systemd/journal/") + } + + return chroot } // ChrootedCallback runs the given callback in a chroot environment