From 30fe521fbd63f2c51cdd406c88a1d909059f72f3 Mon Sep 17 00:00:00 2001 From: Kelvin Fan Date: Wed, 18 Nov 2020 09:45:24 -0500 Subject: [PATCH 1/2] {issuegen,motdgen}.service: `sleep 1` before we start generating This imposes throttling and ensures we're not constantly regenerating when things change quickly (as can happen during system startup). `sleep` in `ExecStartPre` so we capture *all* issue snippets dropped into `/run` in the one second interval. Also set rate limit to once per second so we would never hit any systemd 'start-limit-hit' failures for our .path and .service units. xref https://github.com/coreos/console-login-helper-messages/issues/87 --- .../console-login-helper-messages-issuegen.service | 9 +++++++++ .../system/console-login-helper-messages-motdgen.service | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/usr/lib/systemd/system/console-login-helper-messages-issuegen.service b/usr/lib/systemd/system/console-login-helper-messages-issuegen.service index 618af97..8cc6632 100644 --- a/usr/lib/systemd/system/console-login-helper-messages-issuegen.service +++ b/usr/lib/systemd/system/console-login-helper-messages-issuegen.service @@ -6,6 +6,10 @@ After=console-login-helper-messages-issuegen.path # Only run if source directories have `.issue` files. ConditionPathExistsGlob=|/run/console-login-helper-messages/issue.d/*.issue ConditionPathExistsGlob=|/etc/console-login-helper-messages/issue.d/*.issue +# Set rate limit to twice per second just in case. With `ExecStartPre=` below, +# we should not have any systemd 'start-limit-hit' failures. +StartLimitIntervalSec=1 +StartLimitBurst=2 [Service] Type=oneshot @@ -16,6 +20,11 @@ Type=oneshot # `start` on this service after it has exited once before does not have any # effect). RemainAfterExit=no +# See https://github.com/coreos/console-login-helper-messages/issues/87 +# We want to avoid service start limits and throttle the rate at +# which we regenerate. This ensures the service starts at most once +# per second. +ExecStartPre=sleep 1 ExecStart=/usr/libexec/console-login-helper-messages/issuegen [Install] diff --git a/usr/lib/systemd/system/console-login-helper-messages-motdgen.service b/usr/lib/systemd/system/console-login-helper-messages-motdgen.service index b2bffee..7c249c8 100644 --- a/usr/lib/systemd/system/console-login-helper-messages-motdgen.service +++ b/usr/lib/systemd/system/console-login-helper-messages-motdgen.service @@ -5,6 +5,10 @@ After=console-login-helper-messages-motdgen.path # Only run if source directories have `.motd` files. ConditionPathExistsGlob=|/run/console-login-helper-messages/motd.d/*.motd ConditionPathExistsGlob=|/etc/console-login-helper-messages/motd.d/*.motd +# Set rate limit to twice per second just in case. With `ExecStartPre=` below, +# we should not have any systemd 'start-limit-hit' failures. +StartLimitIntervalSec=1 +StartLimitBurst=2 [Service] Type=oneshot @@ -15,6 +19,11 @@ Type=oneshot # `start` on this service after it has exited once before does not have any # effect). RemainAfterExit=no +# See https://github.com/coreos/console-login-helper-messages/issues/87 +# We want to avoid service start limits and throttle the rate at +# which we regenerate. This ensures the service starts at most once +# per second. +ExecStartPre=sleep 1 ExecStart=/usr/libexec/console-login-helper-messages/motdgen [Install] From ba46ea352241a7d367e9c33f3d4204b8084ab68a Mon Sep 17 00:00:00 2001 From: Kelvin Fan Date: Wed, 18 Nov 2020 13:04:59 -0500 Subject: [PATCH 2/2] tests: Add issuegen test for bursts of issue snippets Tests to ensure that https://github.com/coreos/console-login-helper-messages/issues/87 does not happen. --- tests/kola/basic/test-issue.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/kola/basic/test-issue.sh b/tests/kola/basic/test-issue.sh index 5a027de..0ef484e 100755 --- a/tests/kola/basic/test-issue.sh +++ b/tests/kola/basic/test-issue.sh @@ -36,6 +36,7 @@ ok "symlink" # If SSH keys are present, check that SSH keys snippets were generated by # `gensnippet_ssh_keys` and shown by `agetty`. if test -n "$(find /etc/ssh -name 'ssh_host_*_key' -print -quit)"; then + sleep 2 faketty agetty_output.txt agetty --show-issue assert_file_has_content agetty_output.txt 'SSH host key:*' ok "gensnippet_ssh_keys" @@ -44,9 +45,26 @@ fi # Check that a new issue snippet is generated when a .issue file is dropped into # the issue run directory. echo 'foo' > ${ISSUE_RUN_SNIPPETS_PATH}/10_foo.issue -sleep 1 +sleep 2 faketty agetty_output.txt agetty --show-issue assert_file_has_content agetty_output.txt 'foo' -ok "display new issue snippet" +ok "display new single issue snippet" + +# Check that a large burst of .issue files dropped into the issue run directory +# will all get displayed, and that we don't hit any systemd 'start-limit-hit' +# failures +for i in {1..150}; +do + echo "Issue snippet: $i" > ${ISSUE_RUN_SNIPPETS_PATH}/${i}_spam.issue +done +sleep 2 +faketty agetty_output.txt agetty --show-issue +for i in {1..150}; +do + assert_file_has_content agetty_output.txt "Issue snippet: $i" +done +systemctl status ${PKG_NAME}-issuegen.path > issuegen_status.txt +assert_not_file_has_content issuegen_status.txt "unit-start-limit-hit" +ok "display burst of new issue snippets" tap_finish