]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: enable persistent FD Store to fix logging during soft-reboot
authorLuca Boccassi <bluca@debian.org>
Fri, 31 May 2024 15:40:12 +0000 (16:40 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 3 Jun 2024 15:30:54 +0000 (16:30 +0100)
A unit with StandardOutput=journal (the default) will get its stdout/stderr sockets
disconnected when journald stops, as the file descriptors on journald's side are
not preserved (it works on restart, as the FD Store keeps them open during restarts).
Set FileDescriptorStorePreserve=yes so that the journal FD's stay open during a soft
reboot, and applications don't get broken stdout/stderr.

test/units/TEST-82-SOFTREBOOT.sh
units/systemd-journald.service.in

index 0dc4f87a60b9f96828edf11b2556be54e6ed73f4..f86bc929d046fccaed9ff94bade8d0c8071dd2db 100755 (executable)
@@ -212,6 +212,8 @@ EOF
     # Configure these transient units to survive the soft reboot - they will not conflict with shutdown.target
     # and it will be ignored on the isolate that happens in the next boot. The first will use argv[0][0] =
     # '@', and the second will use SurviveFinalKillSignal=yes. Both should survive.
+    # By writing to stdout, which is connected to the journal, we also ensure logging doesn't break across
+    # soft reboots due to journald being temporarily stopped.
     systemd-run --service-type=notify --unit=TEST-82-SOFTREBOOT-survive-argv.service \
         --property SurviveFinalKillSignal=no \
         --property IgnoreOnIsolate=yes \
@@ -221,6 +223,7 @@ EOF
         --property "Before=reboot.target kexec.target poweroff.target halt.target emergency.target rescue.target" \
         --property SetCredential=preserve:yay \
          "$survive_argv"
+    # shellcheck disable=SC2016
     systemd-run --service-type=exec --unit=TEST-82-SOFTREBOOT-survive.service \
         --property TemporaryFileSystem="/run /tmp /var" \
         --property RootImage=/tmp/minimal_0.raw \
@@ -233,7 +236,7 @@ EOF
         --property After=basic.target \
         --property "Conflicts=reboot.target kexec.target poweroff.target halt.target emergency.target rescue.target" \
         --property "Before=reboot.target kexec.target poweroff.target halt.target emergency.target rescue.target" \
-        sleep infinity
+        bash -c 'count=0; while echo "$count"; do count=$[$count +1]; sleep 1; done'
 
     # Check that we can set up an inhibitor, and that busctl monitor sees the
     # PrepareForShutdownWithMetadata signal and that it says 'soft-reboot'.
index 96362f5730ac754f04c37df22fc3d272060ef72b..4404af963bb42458e07ffc724136960ab4a91a5b 100644 (file)
@@ -32,6 +32,8 @@ IgnoreOnIsolate=yes
 DeviceAllow=char-* rw
 ExecStart={{LIBEXECDIR}}/systemd-journald
 FileDescriptorStoreMax=4224
+# Ensure services using StandardOutput=journal do not break when journald is stopped
+FileDescriptorStorePreserve=yes
 ImportCredential=journal.*
 IPAddressDeny=any
 LockPersonality=yes