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 <hias@horus.com>
This commit is contained in:
Matthias Reichl 2019-09-16 11:21:10 +02:00
parent 28ecf8f4ac
commit 78080a6a46
4 changed files with 22 additions and 19 deletions

View File

@ -185,7 +185,6 @@ post_install() {
enable_service shell.service enable_service shell.service
enable_service show-version.service enable_service show-version.service
enable_service var.mount enable_service var.mount
enable_service var-log-debug.service
enable_service fs-resize.service enable_service fs-resize.service
listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service

View File

@ -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

View File

@ -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

View File

@ -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