Initial clean release: SSE-Connector + Installer
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Watchdog for PMDB SSE Connector (R7-3)
|
||||
#
|
||||
# Single source of truth (per profile):
|
||||
# profile <- $1 (argument, NOT hardcoded)
|
||||
# heartbeat path <- /tmp/pmdb-sse-hb-${PROFILE}
|
||||
# service name <- pmdb-sse-connector@${PROFILE} (systemd user template)
|
||||
#
|
||||
# R7-3 Argument-Bindung: PROFILE wird als erstes Argument übergeben
|
||||
# (crontab: .../watchdog.sh ${PROFILE}). Kein Hardcoding — ein Watchdog je
|
||||
# Profil, der Aufrufer bestimmt das Profil.
|
||||
PROFILE="$1"
|
||||
if [ -z "$PROFILE" ]; then
|
||||
echo "Usage: $0 <profile>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HB_FILE="/tmp/pmdb-sse-hb-${PROFILE}"
|
||||
|
||||
if [ ! -f "$HB_FILE" ]; then
|
||||
echo "Heartbeat file missing for ${PROFILE}, restarting service..."
|
||||
systemctl --user restart "pmdb-sse-connector@${PROFILE}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LAST_HB=$(cat "$HB_FILE")
|
||||
NOW=$(date +%s)
|
||||
|
||||
# R7-3 Vor-Punkt-Arithmetik: %% entfernt das LÄNGSTE Suffix ab dem ERSTEN
|
||||
# Punkt — ein Wert wie "1791785554.546477811791785565.70794762" (mehrere
|
||||
# aneinandergehängte Timestamps, P-NEW-F702-HBSHARE) wird korrekt auf die
|
||||
# Ganzzahl VOR dem ersten Punkt gekürzt (1791785554). Ein einzelnes % würde
|
||||
# nur bis zum LETZTEN Punkt kürzen und einen Float-Rest übrig lassen, an dem
|
||||
# die bash-Arithmetik mit "Ungültiger arithmetischer Operator" crasht.
|
||||
DIFF=$((NOW - ${LAST_HB%%.*}))
|
||||
|
||||
if [ "$DIFF" -gt 300 ]; then
|
||||
echo "Heartbeat outdated (${DIFF}s) for ${PROFILE}, restarting service..."
|
||||
# R7-3 Profil-Suffix-Restart: das Template-Instance-Unit (nicht das
|
||||
# generische pmdb-sse-connector) neustarten, damit nach dem Restart das
|
||||
# richtige Profil-HB-File gelesen wird.
|
||||
systemctl --user restart "pmdb-sse-connector@${PROFILE}"
|
||||
fi
|
||||
Reference in New Issue
Block a user