core: serialize and deserialize unit start ratelimits

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-11-15 17:23:27 +01:00 committed by Luca Boccassi
parent 07a6647abb
commit 6ef512c0bb
3 changed files with 12 additions and 0 deletions

View 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;

View file

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

View file

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