Harden APT boot status reporting

master
Carlo Costanzo 5 days ago
parent 527089babb
commit 440dabaea3

@ -29,7 +29,7 @@ Longer-running shell helpers referenced by automations, packages, or cron. Anyth
| [HAUpdate.sh](HAUpdate.sh) | One-command Home Assistant update helper. | | [HAUpdate.sh](HAUpdate.sh) | One-command Home Assistant update helper. |
| [apt_pending_check.sh](apt_pending_check.sh) | Read-only APT pending-count reporter for the Docker host maintenance dashboard. | | [apt_pending_check.sh](apt_pending_check.sh) | Read-only APT pending-count reporter for the Docker host maintenance dashboard. |
| [apt_weekly.sh](apt_weekly.sh) | Twice-weekly APT updater that posts webhook status and can schedule reboot when needed. | | [apt_weekly.sh](apt_weekly.sh) | Twice-weekly APT updater that posts webhook status and can schedule reboot when needed. |
| [apt_reboot_report.sh](apt_reboot_report.sh) | Boot-time webhook status reporter that clears/keeps reboot-required state in HA. | | [apt_reboot_report.sh](apt_reboot_report.sh) | Boot-time status reporter that reuses the registered APT webhook, retries while HA starts, and clears/keeps reboot-required state. |
| [gitupdate.sh](gitupdate.sh) | Pull the latest config changes on demand. | | [gitupdate.sh](gitupdate.sh) | Pull the latest config changes on demand. |
| [![YAML source: basketball](https://img.shields.io/static/v1?label=YAML&message=basketball&color=lightgrey&logo=github&logoColor=181717)](basketball.yaml) | ESPN stat scraping helper used by sensors. | | [![YAML source: basketball](https://img.shields.io/static/v1?label=YAML&message=basketball&color=lightgrey&logo=github&logoColor=181717)](basketball.yaml) | ESPN stat scraping helper used by sensors. |
| [Jinja Code.py](Jinja Code.py) | Reference Jinja snippets for templating. | | [Jinja Code.py](Jinja Code.py) | Reference Jinja snippets for templating. |

@ -0,0 +1,15 @@
[Unit]
Description=Report boot completion for APT reboot tracking
After=network-online.target docker.service
Wants=network-online.target
ConditionPathExists=/usr/local/sbin/apt_weekly.sh
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/apt_reboot_report.sh --from-apt-weekly
User=root
Group=root
TimeoutStartSec=330
[Install]
WantedBy=multi-user.target

@ -2,13 +2,28 @@
set -euo pipefail set -euo pipefail
# Boot report for APT-managed hosts. # Boot report for APT-managed hosts.
# Sends current reboot-required state after each system boot. # Reuses the registered apt_weekly webhook and retries while Home Assistant starts.
WEBHOOK_URL="$1" WEBHOOK_SOURCE="${1:-}"
HOST_NAME="${2:-$(hostname -s)}" HOST_NAME="${2:-$(hostname -s)}"
case "$HOST_NAME" in
docker10) HOST_NAME="docker_10" ;;
docker14) HOST_NAME="docker_14" ;;
docker17) HOST_NAME="docker_17" ;;
docker69) HOST_NAME="docker_69" ;;
esac
if [[ "$WEBHOOK_SOURCE" == "--from-apt-weekly" ]]; then
WEEKLY_EXEC_START="$(systemctl show apt_weekly.service --property=ExecStart --value 2>/dev/null || true)"
WEBHOOK_URL="$(printf '%s\n' "$WEEKLY_EXEC_START" | grep -Eo 'https?://[^ ;]+' | head -n 1 || true)"
else
WEBHOOK_URL="$WEBHOOK_SOURCE"
fi
if [[ -z "$WEBHOOK_URL" ]]; then if [[ -z "$WEBHOOK_URL" ]]; then
echo "Usage: $0 <webhook_url> [host_name]" >&2 echo "Usage: $0 <webhook_url|--from-apt-weekly> [host_name]" >&2
echo "Unable to resolve the registered APT webhook." >&2
exit 1 exit 1
fi fi
@ -26,4 +41,15 @@ payload=$(cat <<JSON
JSON JSON
) )
curl -sS -X POST -H 'Content-Type: application/json' -d "$payload" "$WEBHOOK_URL" || true curl --fail --silent --show-error \
--connect-timeout 5 \
--max-time 20 \
--retry 30 \
--retry-delay 10 \
--retry-connrefused \
--retry-all-errors \
--retry-max-time 300 \
-X POST \
-H 'Content-Type: application/json' \
-d "$payload" \
"$WEBHOOK_URL"

Loading…
Cancel
Save

Powered by TurnKey Linux.