From 78080a6a465f7e1fd8e8d94acdb9fc217c013159 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Mon, 16 Sep 2019 11:21:10 +0200 Subject: [PATCH 1/2] busybox: cleanup persistent log setup when debugging is enabled The ancient approach of symlinking /var/log to /storage/log doesn't play nice with systemd as it doesn't setup proper dependencies and unmounting /storage during shutdown may fail because systemd doesn't know that it's needed for /var/log. Use a conditional bind mount instead so systemd can automatically create proper dependencies and unmount filesystems in the correct order. Also store the persistent logfiles on /storage in a .cache/log directory instead of log to avoid confusing users - users can access logfiles via /var/log. Note: we can't use tmpfiles.d to create the .cache/log directory on /storage because that would run after local-fs.target but we need the .log directory before that so it has to be done via a one-shot service. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 1 - .../busybox/system.d/storage-log.service | 9 +++++++++ .../busybox/system.d/var-log-debug.service | 18 ------------------ .../sysutils/busybox/system.d/var-log.mount | 13 +++++++++++++ 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 packages/sysutils/busybox/system.d/storage-log.service delete mode 100644 packages/sysutils/busybox/system.d/var-log-debug.service create mode 100644 packages/sysutils/busybox/system.d/var-log.mount diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 7968b13155..498b0125de 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -185,7 +185,6 @@ post_install() { enable_service shell.service enable_service show-version.service enable_service var.mount - enable_service var-log-debug.service enable_service fs-resize.service listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service diff --git a/packages/sysutils/busybox/system.d/storage-log.service b/packages/sysutils/busybox/system.d/storage-log.service new file mode 100644 index 0000000000..d27d0a31df --- /dev/null +++ b/packages/sysutils/busybox/system.d/storage-log.service @@ -0,0 +1,9 @@ +[Unit] +Description=Create Persistent Log Directory on /storage +DefaultDependencies=no +RequiresMountsFor=/storage + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/mkdir -p /storage/.cache/log/journal diff --git a/packages/sysutils/busybox/system.d/var-log-debug.service b/packages/sysutils/busybox/system.d/var-log-debug.service deleted file mode 100644 index a8e9efc0fd..0000000000 --- a/packages/sysutils/busybox/system.d/var-log-debug.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Debug /var/log relink -DefaultDependencies=false -After=var.mount -Before=systemd-journal-flush.service -ConditionKernelCommandLine=!installer -ConditionKernelCommandLine=|debugging -ConditionPathExists=|/storage/.cache/debug.libreelec - -[Service] -Type=oneshot -ExecStartPre=/bin/rm -rf /var/log -ExecStartPre=-/bin/mkdir -p /storage/log/journal -ExecStart=-/bin/ln -sf /storage/log /var/log -RemainAfterExit=yes - -[Install] -WantedBy=sysinit.target diff --git a/packages/sysutils/busybox/system.d/var-log.mount b/packages/sysutils/busybox/system.d/var-log.mount new file mode 100644 index 0000000000..e6b6ebf88b --- /dev/null +++ b/packages/sysutils/busybox/system.d/var-log.mount @@ -0,0 +1,13 @@ +[Unit] +Description=Persistent Log Storage +RequiresMountsFor=/var /storage +Requires=storage-log.service +After=storage-log.service +ConditionKernelCommandLine=!installer +ConditionKernelCommandLine=|debugging +ConditionPathExists=|/storage/.cache/debug.libreelec + +[Mount] +What=/storage/.cache/log +Where=/var/log +Options=bind From 707b974d76965e94f1f8ec41c954ebad21eca171 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Mon, 16 Sep 2019 20:16:44 +0200 Subject: [PATCH 2/2] busybox: add workaround for systemd issue 867 journald on systemd versions up to 242 don't close the persistent journal files on shutdown which leads to a harmless but annoying Failed unmounting message during shutdown https://github.com/systemd/systemd/issues/867 Set LazyUnmount=yes on the persistent log mount unit as a temporary workaround until systemd is updated to 243 or newer. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/system.d/var-log.mount | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sysutils/busybox/system.d/var-log.mount b/packages/sysutils/busybox/system.d/var-log.mount index e6b6ebf88b..3acdd0a6de 100644 --- a/packages/sysutils/busybox/system.d/var-log.mount +++ b/packages/sysutils/busybox/system.d/var-log.mount @@ -11,3 +11,4 @@ ConditionPathExists=|/storage/.cache/debug.libreelec What=/storage/.cache/log Where=/var/log Options=bind +LazyUnmount=yes