Aggiorna script backup e bot meteo Telegram.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a7b867e83
commit
beb790ed7e
6 files changed
+350
-102
No files matched your search
@@ -1,16 +1,50 @@
|
||||
#!/bin/bash
|
||||
# raspiBackup post extension — notifica Loogle Casa (solo WebApp).
|
||||
#
|
||||
# RaspiBackup chiama il post hook PRIMA di STARTSERVICES: su Pi2 Casa è giù
|
||||
# (before-stop ferma loogle-casa, STOPSERVICES ferma docker). Non notificare
|
||||
# subito: systemd-run stacca dal cgroup e riprova finché l'API risponde.
|
||||
#
|
||||
# Sourced da raspiBackup: $1 = return code backup.
|
||||
# Eseguito da systemd-run: $1 = --wait-send
|
||||
|
||||
LOOGLE_NOTIFY="/home/daniely/docker/loogle-casa/scripts/loogle-notify.sh"
|
||||
MAX_TRIES="${LOOGLE_BACKUP_NOTIFY_TRIES:-36}"
|
||||
SLEEP_SECS="${LOOGLE_BACKUP_NOTIFY_SLEEP:-5}"
|
||||
|
||||
wait_send() {
|
||||
local title="$1" body="$2" severity="$3" tag="$4"
|
||||
local i
|
||||
if [[ ! -x "$LOOGLE_NOTIFY" ]]; then
|
||||
echo "loogle-notify.sh assente" >&2
|
||||
exit 0
|
||||
fi
|
||||
for ((i = 1; i <= MAX_TRIES; i++)); do
|
||||
if "$LOOGLE_NOTIFY" --title "$title" --body "$body" --category raspi_backup \
|
||||
--severity "$severity" --tag "$tag"; then
|
||||
echo "notify ok try=$i tag=$tag"
|
||||
exit 0
|
||||
fi
|
||||
echo "notify retry $i/$MAX_TRIES tag=$tag" >&2
|
||||
sleep "$SLEEP_SECS"
|
||||
done
|
||||
echo "notify failed after ${MAX_TRIES} tries tag=$tag" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "--wait-send" ]]; then
|
||||
wait_send "${2:-}" "${3:-}" "${4:-info}" "${5:-raspi_backup}"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
RC="${1:-1}"
|
||||
LOOGLE_NOTIFY="/home/daniely/docker/loogle-casa/scripts/loogle-notify.sh"
|
||||
HOST="${HOSTNAME:-$(hostname)}"
|
||||
HOST="${HOST%%.*}"
|
||||
|
||||
if [[ ! -x "$LOOGLE_NOTIFY" ]]; then
|
||||
return 0 2>/dev/null || exit 0
|
||||
fi
|
||||
|
||||
HOST="${HOSTNAME:-$(hostname)}"
|
||||
|
||||
if (( RC == 0 )); then
|
||||
TITLE="Backup completato"
|
||||
BODY="Backup di ${HOST} terminato con successo."
|
||||
@@ -21,7 +55,19 @@ else
|
||||
SEVERITY="error"
|
||||
fi
|
||||
|
||||
"$LOOGLE_NOTIFY" --title "$TITLE" --body "$BODY" --category raspi_backup \
|
||||
--severity "$SEVERITY" &
|
||||
TAG="raspi_backup-${HOST}"
|
||||
SELF="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || echo /usr/local/bin/raspiBackup_loogle_post.sh)"
|
||||
|
||||
# Stacca dal servizio raspiBackup (KillMode=control-group) e aspetta Casa.
|
||||
if command -v systemd-run >/dev/null 2>&1; then
|
||||
systemd-run --quiet --collect \
|
||||
--description="Loogle Casa raspiBackup notify ${HOST}" \
|
||||
/bin/bash "$SELF" --wait-send "$TITLE" "$BODY" "$SEVERITY" "$TAG" \
|
||||
|| true
|
||||
else
|
||||
nohup /bin/bash "$SELF" --wait-send "$TITLE" "$BODY" "$SEVERITY" "$TAG" \
|
||||
>/dev/null 2>&1 &
|
||||
disown 2>/dev/null || true
|
||||
fi
|
||||
|
||||
return 0 2>/dev/null || exit 0
|
||||
Reference in new issue
Block a user