Enhance docker infrastructure automation with staggered auto-reboot functionality and update README. Added support for scheduling reboots in the APT weekly script and introduced boot report automations for docker hosts. #1539

This commit is contained in:
Carlo Costanzo
2026-02-11 10:58:13 -05:00
parent 84d638c1fc
commit 799a73dd7e
7 changed files with 193 additions and 10 deletions

View File

@@ -27,6 +27,8 @@ Longer-running shell helpers referenced by automations, packages, or cron. Anyth
| File | Why it matters |
| --- | --- |
| [HAUpdate.sh](HAUpdate.sh) | One-command Home Assistant update helper. |
| [apt_weekly.sh](apt_weekly.sh) | 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. |
| [gitupdate.sh](gitupdate.sh) | Pull the latest config changes on demand. |
| [basketball.yaml](basketball.yaml) | ESPN stat scraping helper used by sensors. |
| [Jinja Code.py](Jinja Code.py) | Reference Jinja snippets for templating. |

View File

@@ -0,0 +1,13 @@
[Unit]
Description=Report boot completion for APT reboot tracking
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/apt_reboot_report.sh https://HOMEASSISTANT_HOST:8123/api/webhook/REPLACE_WITH_BOOT_WEBHOOK_ID docker_10
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
# Boot report for APT-managed hosts.
# Sends current reboot-required state after each system boot.
WEBHOOK_URL="$1"
HOST_NAME="${2:-$(hostname -s)}"
if [[ -z "$WEBHOOK_URL" ]]; then
echo "Usage: $0 <webhook_url> [host_name]" >&2
exit 1
fi
REBOOT_REQUIRED=false
if [[ -f /var/run/reboot-required ]]; then
REBOOT_REQUIRED=true
fi
payload=$(cat <<JSON
{
"event": "boot_report",
"host": "${HOST_NAME}",
"reboot_required": $( $REBOOT_REQUIRED && echo true || echo false )
}
JSON
)
curl -sS -X POST -H 'Content-Type: application/json' -d "$payload" "$WEBHOOK_URL" || true

View File

@@ -5,7 +5,7 @@ Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/apt_weekly.sh https://HOMEASSISTANT_HOST:8123/api/webhook/REPLACE_WITH_WEBHOOK_ID
ExecStart=/usr/local/sbin/apt_weekly.sh https://HOMEASSISTANT_HOST:8123/api/webhook/REPLACE_WITH_APT_WEBHOOK_ID docker_10 20
User=root
Group=root
Nice=10

View File

@@ -2,15 +2,27 @@
set -euo pipefail
# Weekly APT maintenance for docker hosts (runs Wednesdays at 12:00 local via systemd timer)
# Posts results to Home Assistant webhook.
# Posts results to Home Assistant webhook and optionally schedules reboot when required.
WEBHOOK_URL="$1"
HOST_NAME="${2:-$(hostname -s)}"
REBOOT_DELAY_MINUTES="${3:-}"
if [[ -z "$WEBHOOK_URL" ]]; then
echo "Usage: $0 <webhook_url>" >&2
echo "Usage: $0 <webhook_url> [host_name] [reboot_delay_minutes]" >&2
exit 1
fi
AUTO_REBOOT=false
if [[ -n "$REBOOT_DELAY_MINUTES" ]]; then
if [[ "$REBOOT_DELAY_MINUTES" =~ ^[0-9]+$ ]]; then
AUTO_REBOOT=true
else
echo "reboot_delay_minutes must be a non-negative integer" >&2
exit 1
fi
fi
log() { echo "[$(date --iso-8601=seconds)] $*"; }
UPDATED=false
@@ -45,10 +57,13 @@ fi
payload=$(cat <<JSON
{
"host": "${HOST_NAME}",
"success": $( [[ "$MESSAGE" == "" ]] && echo true || echo false ),
"updated": $( $UPDATED && echo true || echo false ),
"packages": $PACKAGES,
"reboot_required": $( $REBOOT && echo true || echo false ),
"auto_reboot_scheduled": $( [[ "$REBOOT" == true && "$AUTO_REBOOT" == true && "$MESSAGE" == "" ]] && echo true || echo false ),
"reboot_delay_minutes": ${REBOOT_DELAY_MINUTES:-0},
"message": "${MESSAGE}"
}
JSON
@@ -56,3 +71,14 @@ JSON
log "Posting results to Home Assistant"
curl -sS -X POST -H 'Content-Type: application/json' -d "$payload" "$WEBHOOK_URL" || true
if [[ "$REBOOT" == true && "$AUTO_REBOOT" == true && "$MESSAGE" == "" ]]; then
shutdown -c >/dev/null 2>&1 || true
if [[ "$REBOOT_DELAY_MINUTES" -eq 0 ]]; then
log "Reboot required; rebooting immediately."
shutdown -r now "APT weekly maintenance reboot"
else
log "Reboot required; scheduling reboot in ${REBOOT_DELAY_MINUTES} minute(s)."
shutdown -r +"$REBOOT_DELAY_MINUTES" "APT weekly maintenance reboot"
fi
fi