core: serialize and deserialize unit start ratelimits
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Nov 2023 16:23:27 +0000 (17:23 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 22 Nov 2023 12:12:35 +0000 (12:12 +0000)
The logic is taken from dump ratelimit: if the config changes, we discard the
counters. This allows the user apply new limits and "start from scratch" in
that case.

This actually makes StartLimitIntervalSec=infinity (or with a large interval)
work as expected, because the counter is maintained even if daemon-reload
operations are interleaved.

src/core/unit-serialize.c
test/units/testsuite-04.SYSTEMD_JOURNAL_COMPRESS.sh
test/units/testsuite-67.sh

index af3e1c2..bef3654 100644 (file)
@@ -140,6 +140,8 @@ int unit_serialize_state(Unit *u, FILE *f, FDSet *fds, bool switching_root) {
         (void) serialize_dual_timestamp(f, "condition-timestamp", &u->condition_timestamp);
         (void) serialize_dual_timestamp(f, "assert-timestamp", &u->assert_timestamp);
 
+        (void) serialize_ratelimit(f, "start-ratelimit", &u->start_ratelimit);
+
         if (dual_timestamp_is_set(&u->condition_timestamp))
                 (void) serialize_bool(f, "condition-result", u->condition_result);
 
@@ -343,6 +345,10 @@ int unit_deserialize_state(Unit *u, FILE *f, FDSet *fds) {
                         (void) deserialize_dual_timestamp(v, &u->assert_timestamp);
                         continue;
 
+                } else if (streq(l, "start-ratelimit")) {
+                        deserialize_ratelimit(&u->start_ratelimit, l, v);
+                        continue;
+
                 } else if (MATCH_DESERIALIZE("condition-result", l, v, parse_boolean, u->condition_result))
                         continue;
 
index 8fdf1b1..96d096d 100755 (executable)
@@ -7,6 +7,9 @@ set -o pipefail
 mkdir /run/systemd/system/systemd-journald.service.d
 MACHINE_ID="$(</etc/machine-id)"
 
+# Reset the start-limit counters, as we're going to restart journald a couple of times
+systemctl reset-failed systemd-journald.service
+
 for c in NONE XZ LZ4 ZSTD; do
     cat >/run/systemd/system/systemd-journald.service.d/compress.conf <<EOF
 [Service]
@@ -35,4 +38,5 @@ done
 rm /run/systemd/system/systemd-journald.service.d/compress.conf
 systemctl daemon-reload
 systemctl restart systemd-journald.service
+systemctl reset-failed systemd-journald.service
 journalctl --rotate
index ca1cbe4..a42fd66 100755 (executable)
@@ -88,6 +88,8 @@ do
     # Make sure we are in a consistent state, e.g. not already active before we start
     systemctl stop systemd-integritysetup@"${DM_NAME}".service || exit 1
     systemctl start systemd-integritysetup@"${DM_NAME}".service || exit 1
+    # Reset the start-limit counters, as we're going to restart the service a couple of times
+    systemctl reset-failed systemd-integritysetup@"${DM_NAME}".service
 
     # Check the signature on the FS to ensure we can retrieve it and that is matches
     if [ -e "${FULL_DM_DEV_NAME}" ]; then