heal.sh now: 1. git fetch + reset --hard origin/main when remote is ahead 2. writes web/data/deploy.json (sha + timestamp) after each pull 3. nginx reload if web/ files changed 4. falls back to writing deploy.json on first run if missing spec/index.html shows deployed commit SHA + timestamp in footer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
1.4 KiB
Bash
Executable file
37 lines
1.4 KiB
Bash
Executable file
#!/bin/bash
|
|
# Self-heal: pull latest git changes, deploy web content, keep containers up.
|
|
# Runs every 5 minutes via systemd timer.
|
|
set -euo pipefail
|
|
cd /opt/xetup
|
|
|
|
LOG="[heal $(date '+%H:%M:%S')]"
|
|
|
|
# Pull latest changes (ff-only: never merge, just update)
|
|
BEFORE=$(git rev-parse HEAD 2>/dev/null || echo "none")
|
|
git fetch --quiet origin main 2>/dev/null || true
|
|
REMOTE=$(git rev-parse origin/main 2>/dev/null || echo "")
|
|
|
|
if [ -n "$REMOTE" ] && [ "$BEFORE" != "$REMOTE" ]; then
|
|
git reset --hard origin/main --quiet 2>/dev/null || true
|
|
AFTER=$(git rev-parse HEAD)
|
|
echo "$LOG deployed $BEFORE → $AFTER"
|
|
|
|
# Write deployed commit info for the web (spec page footer)
|
|
echo "{\"sha\":\"$(git rev-parse --short HEAD)\",\"ts\":\"$(date -u '+%Y-%m-%dT%H:%M:%SZ')\"}" \
|
|
> web/data/deploy.json
|
|
|
|
# If web content changed, reload nginx config
|
|
if git diff --name-only "$BEFORE" "$AFTER" 2>/dev/null | grep -q '^web/'; then
|
|
echo "$LOG web/ changed - reloading nginx"
|
|
/usr/bin/docker compose exec -T web nginx -s reload 2>/dev/null || true
|
|
fi
|
|
else
|
|
# Always keep deploy.json fresh on first run if missing
|
|
if [ ! -f web/data/deploy.json ]; then
|
|
echo "{\"sha\":\"$(git rev-parse --short HEAD)\",\"ts\":\"$(date -u '+%Y-%m-%dT%H:%M:%SZ')\"}" \
|
|
> web/data/deploy.json
|
|
fi
|
|
fi
|
|
|
|
# Ensure all containers are running
|
|
/usr/bin/docker compose up -d --remove-orphans 2>&1 | grep -v "up-to-date\|unchanged" || true
|