From 55594274f78d20b2d86c3bc683d7c27d7cde60c2 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Thu, 15 Dec 2022 18:12:06 -0300 Subject: [PATCH] Fix journalctl to work with persistent logs v14.4.5 introduced a new way to retrieve the host logs by symlinking the log directories into the host /run/log/journal and using a local copy of the journalctl binary instead of chrooting into the host. This failed to account for the location of persistent logs when that option is turned on (/var/log/journal instead of /run/log/journal). This fixes the checks consider this case and also makes sure to remove the original symlink to avoid having nested links `/run/log/journal/journal/journal`, which was a bug in the previous implementation. Change-type: patch --- entry.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/entry.sh b/entry.sh index 974dbf5a..54fa2ae0 100755 --- a/entry.sh +++ b/entry.sh @@ -30,10 +30,23 @@ fi # NOTE: this won't be necessary once the supervisor can update # itself, as using the label io.balena.features.journal-logs will # achieve the same objective -if [ -d /mnt/root/run/log/journal ]; then +if { [ ! -d /run/log/journal ] || [ -L /run/log/journal ]; } && [ -s /mnt/root/etc/machine-id ]; then + # Only enter here if the directory does not exist or the location exists and is a symlink + # (note that test -d /symlink-to-dir will return true) + + # Create the directory mkdir -p /run/log - ln -sf /mnt/root/run/log/journal /run/log/journal + + # Override the local machine-id ln -sf /mnt/root/etc/machine-id /etc/machine-id + + # Remove the original link if it exists to avoid creating deep links + [ -L /run/log/journal ] && rm /run/log/journal + + # If using persistent logging, the host will the journal under `/var/log/journal` + # otherwise it will have it under /run/log/journal + [ -d "/mnt/root/run/log/journal/$(cat /etc/machine-id)" ] && ln -sf /mnt/root/run/log/journal /run/log/journal + [ -d "/mnt/root/var/log/journal/$(cat /etc/machine-id)" ] && ln -sf /mnt/root/var/log/journal /run/log/journal fi # Mount the host kernel module path onto the expected location