From dec9bbdffee0e781fac53cf40409351280838c15 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 18 Feb 2024 23:43:59 +1100 Subject: [PATCH] healthcheck improvements for system user units --- healthcheck/systemd-user-timers | 17 --------------- healthcheck/systemd-user-units | 37 +++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 23 deletions(-) delete mode 100755 healthcheck/systemd-user-timers diff --git a/healthcheck/systemd-user-timers b/healthcheck/systemd-user-timers deleted file mode 100755 index e4679e7..0000000 --- a/healthcheck/systemd-user-timers +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -cd ~/.config/systemd/user/ &> /dev/null || exit 0 - -error=0 -for timer in *.timer; do - if ! systemctl --user is-enabled "$timer" > /dev/null; then - echo "disabled timer $timer" - error=1 - fi - if ! systemctl --user is-active "$timer" > /dev/null; then - echo "inactive timer $timer" - error=1 - fi -done - -exit "$error" diff --git a/healthcheck/systemd-user-units b/healthcheck/systemd-user-units index ddc1551..4322734 100755 --- a/healthcheck/systemd-user-units +++ b/healthcheck/systemd-user-units @@ -1,9 +1,34 @@ #!/bin/bash -if systemctl --user is-system-running > /dev/null; then - exit 0 -fi +users="$(systemctl list-units | \ + sed -nE 's/.*user@([0-9]+)\.service .*loaded active running.*/\1/p' | \ + xargs -n1 id -un)" -echo -e "# systemctl --user --failed" -systemctl --user --failed -exit 1 +error=0 +for user in $users; do + homedir="$(getent passwd "$user"|cut -d: -f6)" + for timer in "$homedir"/.config/systemd/user/*.timer; do + if ! [ -f "$timer" ]; then + continue + fi + timerunit="$(basename "$timer")" + if ! systemctl --user -M"$user@" is-enabled "$timerunit" > /dev/null; then + echo "disabled timer $timer" + error=1 + fi + if ! systemctl --user -M"$user@" is-active "$timerunit" > /dev/null; then + echo "inactive timer $timer" + error=1 + fi + done + + if systemctl --user -M "$user@" is-system-running > /dev/null; then + continue + fi + + echo -e "# systemctl --user -M "$user@" --failed" + systemctl --user -M "$user@" --failed + error=1 +done + +exit "$error" -- 2.39.2