Consolidate config into sky-cam.conf; systemd failure notifications

sky-cam.conf (new)
- Single file replaces mattermost_config.txt reference, notify_config.txt,
  and the hardcoded BASE_DIR/MUSIC_DIR/TIMEZONE scattered across scripts
- Bash-sourceable and Python key=value readable (same format)

All .sh scripts
- source sky-cam.conf at startup; BASE_DIR / MUSIC_DIR from config

sunrise2mm.py
- Reads sky-cam.conf relative to script location; no hardcoded path

notify.sh
- Sources sky-cam.conf; Mattermost credentials come from there directly,
  no separate mattermost_config.txt lookup needed

systemd/sky-cam-notify-failure@.service (new)
- Template unit called by OnFailure= in each service
- Sends notification via notify.sh when any sky-cam job fails
- All three .service units now have OnFailure=sky-cam-notify-failure@%n.service

Removed: notify_config.txt, sky-cam.crontab (superseded)

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
Claude
2026-04-18 17:11:06 +00:00
parent 8617248cc0
commit ac01c05948
13 changed files with 72 additions and 76 deletions
+11 -20
View File
@@ -10,19 +10,18 @@
set -euo pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
CONFIG="$SCRIPT_DIR/notify_config.txt"
CONFIG="$SCRIPT_DIR/sky-cam.conf"
TITLE="${1:-Sky-Cam notification}"
BODY="${2:-}"
# ── Load config ───────────────────────────────────────────────────────────────
if [ ! -f "$CONFIG" ]; then
echo "notify.sh: config not found at $CONFIG — skipping notifications" >&2
echo "notify.sh: sky-cam.conf not found — skipping notifications" >&2
exit 0
fi
# Source only the known keys; ignore comments and blank lines.
eval "$(grep -E '^[A-Z_]+=.*' "$CONFIG" | grep -v '^#')"
source "$CONFIG"
NTFY_ENABLED="${NTFY_ENABLED:-false}"
NTFY_URL="${NTFY_URL:-}"
@@ -52,23 +51,15 @@ if [ "$EMAIL_ENABLED" = "true" ] && [ -n "$EMAIL_TO" ]; then
fi
# ── Mattermost text post ──────────────────────────────────────────────────────
# Uses the same mattermost_config.txt as sunrise2mm.py but posts to
# MM_NOTIFY_CHANNEL_ID (can be the same channel or a private admin channel).
# mattermost_url and access_token come from sky-cam.conf (sourced above).
if [ "$MM_NOTIFY_ENABLED" = "true" ] && [ -n "$MM_NOTIFY_CHANNEL_ID" ]; then
MM_CONFIG="/home/motion/drives/local-2tb/sunrise-scripts/mattermost_config.txt"
[ ! -f "$MM_CONFIG" ] && MM_CONFIG="$SCRIPT_DIR/mattermost_config.txt"
if [ -f "$MM_CONFIG" ]; then
eval "$(grep -E '^(mattermost_url|access_token)=' "$MM_CONFIG")"
curl -s \
-H "Authorization: Bearer $access_token" \
-H "Content-Type: application/json" \
-d "{\"channel_id\":\"$MM_NOTIFY_CHANNEL_ID\",\"message\":\"**$TITLE**\n$BODY\"}" \
"${mattermost_url}/api/v4/posts" > /dev/null \
&& echo "notify: mattermost sent" \
|| echo "notify: mattermost failed" >&2
else
echo "notify: mattermost_config.txt not found — skipping MM notify" >&2
fi
curl -s \
-H "Authorization: Bearer $access_token" \
-H "Content-Type: application/json" \
-d "{\"channel_id\":\"$MM_NOTIFY_CHANNEL_ID\",\"message\":\"**$TITLE**\n$BODY\"}" \
"${mattermost_url}/api/v4/posts" > /dev/null \
&& echo "notify: mattermost sent" \
|| echo "notify: mattermost failed" >&2
fi
exit 0