Last active
July 25, 2024 03:51
-
-
Save fidgetingbits/a9c9d4786dd28c0f5224071280edfb66 to your computer and use it in GitHub Desktop.
talon systemd user service and associated watchdog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❯ cat /home/aa/.config/systemd/user/talon.service | |
File: /home/aa/.config/systemd/user/talon.service | |
[Install] | |
WantedBy=graphical-session.target | |
[Service] | |
ExecStart=/nix/store/3j9rf4s7ldqq79xa92x73yqlp9885zzd-talon/bin/talon | |
Restart=always | |
[Unit] | |
After=graphical-session-pre.target | |
Description=Talon Voice | |
Documentation=https://talonvoice.com/ | |
PartOf=graphical-session.target | |
❯ cat /home/aa/.config/systemd/user/talon-watchdog.service | |
File: /home/aa/.config/systemd/user/talon-watchdog.service | |
[Install] | |
WantedBy=graphical-session.target | |
[Service] | |
ExecStart=/nix/store/8cjr85lgl69bwrvi2nlhf841g39mkvsl-talon-watchdog/bin/talon-watchdog | |
Restart=on-failure | |
[Unit] | |
After=talon.target | |
Description=Talon Voice Watchdog | |
Documentation=https://talonvoice.com/ | |
PartOf=graphical-session.target | |
❯ cat /nix/store/8cjr85lgl69bwrvi2nlhf841g39mkvsl-talon-watchdog/bin/talon-watchdog | |
File: /nix/store/8cjr85lgl69bwrvi2nlhf841g39mkvsl-talon-watchdog/bin/talon-watchdog | |
#!/nix/store/5jw69mbaj5dg4l2bj58acg3gxywfszpj-bash-5.2p26/bin/bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
export PATH="/nix/store/lizkknvmwjda1g2lshys5av0kbxir97g-inotify-tools-4.23.9.0/bin:/nix/store/ysqx2xfzygv2rxl7nxnw48276z5ckppn-coreutils-9.5/bin:/nix/store/x3dw5h8zds2m4qb2c332h4sxp0qllq | |
ld-talon-notify/bin:$PATH" | |
#!/usr/bin/env bash | |
set -euo pipefail | |
LOG_FILE=$HOME/.talon/talon.log | |
NOTIFY_THRESHOLD=10 | |
RESTART_THRESHOLD=60 | |
notified=false | |
while true; do | |
inotifywait -e modify "${LOG_FILE}" >/dev/null 2>&1 | |
tail -n 10 "${LOG_FILE}" | while read -r line; do | |
if [[ ${line} == *"(stalled)"* ]]; then | |
count=$(echo "${line}" | cut -d@ -f2 | cut -ds -f1 | cut -d. -f1) | |
# Keep the count high in case we are running certain scripts | |
if [[ ${count} -ge $RESTART_THRESHOLD ]]; then | |
talon-notify "Talon auto-restarting" | |
systemctl --user restart talon | |
sleep 5 | |
notified=false | |
elif [[ ${count} -ge $NOTIFY_THRESHOLD ]] && [[ $notified == false ]]; then | |
talon-notify "Talon stalled. Will auto-restart after ${RESTART_THRESHOLD}s" | |
# FIXME: We should use a notification that allows you to collect yes or no to restart | |
# gnome-shell doesn't support expiry time, so we can rely on an action for now, unless we used | |
# something like dunst | |
sleep 5 | |
notified=true | |
fi | |
fi | |
done | |
# This $? comes from exit in the read line while loop above | |
if [[ $? == 1 ]]; then | |
exit 1 | |
fi | |
done | |
❯ cat /nix/store/x3dw5h8zds2m4qb2c332h4sxp0qllqld-talon-notify/bin/talon-notify | |
File: /nix/store/x3dw5h8zds2m4qb2c332h4sxp0qllqld-talon-notify/bin/talon-notify | |
#!/nix/store/5jw69mbaj5dg4l2bj58acg3gxywfszpj-bash-5.2p26/bin/bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
export PATH="/nix/store/fzfzz1m1s66hnmccnn02q3bq5g2na9d7-libnotify-0.8.3/bin:$PATH" | |
#shellcheck disable=SC2086,SC2068 | |
/nix/store/fzfzz1m1s66hnmccnn02q3bq5g2na9d7-libnotify-0.8.3/bin/notify-send -i /nix/store/7jj38alx7l62ig1vrqrbzacfl4ppqyzp-talon-48x48.png "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment