From 51eeff37fb9de8d5b0bce8e26036ed2a95787b4f Mon Sep 17 00:00:00 2001 From: Mark Eaton Date: Sun, 16 Nov 2025 01:14:02 -0500 Subject: [PATCH] feat: add catch-up systemd timer and runner script for main.py Co-authored-by: aider (openai/gpt-5) --- scripts/run_main.sh | 12 ++++++++++++ systemd/libguides-notifier.service | 14 ++++++++++++++ systemd/libguides-notifier.timer | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 scripts/run_main.sh create mode 100644 systemd/libguides-notifier.service create mode 100644 systemd/libguides-notifier.timer diff --git a/scripts/run_main.sh b/scripts/run_main.sh new file mode 100644 index 0000000..73bb4f3 --- /dev/null +++ b/scripts/run_main.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Change to the repository root (one level up from this script's directory) +cd "$(dirname "$0")/.." + +# Prefer uv if available (uses pyproject.toml/uv.lock), otherwise fall back to system Python. +if command -v uv >/dev/null 2>&1; then + uv run python -u main.py +else + python3 -u main.py +fi diff --git a/systemd/libguides-notifier.service b/systemd/libguides-notifier.service new file mode 100644 index 0000000..fb76139 --- /dev/null +++ b/systemd/libguides-notifier.service @@ -0,0 +1,14 @@ +# User-level systemd service to run main.py +# Uses a wrapper script so the working directory and .env are found correctly. +# Replace REPO_PATH automatically using the setup command we provide. +[Unit] +Description=Run main.py (LibGuides notifier) +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecStart="REPO_PATH/scripts/run_main.sh" + +[Install] +WantedBy=default.target diff --git a/systemd/libguides-notifier.timer b/systemd/libguides-notifier.timer new file mode 100644 index 0000000..67b2736 --- /dev/null +++ b/systemd/libguides-notifier.timer @@ -0,0 +1,17 @@ +# User-level systemd timer that "catches up" missed runs if the machine was off. +[Unit] +Description=Schedule main.py with catch-up if missed + +[Timer] +# Change this to your desired schedule; examples: +# OnCalendar=daily +# OnCalendar=Mon..Fri 09:00 +# See man systemd.time for syntax. +OnCalendar=hourly +Persistent=true +AccuracySec=1m +RandomizedDelaySec=5m +Unit=libguides-notifier.service + +[Install] +WantedBy=timers.target