mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2026-07-03 21:08:41 -07:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user