54 lines
1.3 KiB
Bash
Executable File
54 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Keep the port-80 live.local edge proxy available after network/service drift.
|
|
set -Eeuo pipefail
|
|
|
|
ROOT_DIR="${LIVE_STACK_ROOT:-/opt/live/d2ypp}"
|
|
STACK_ENV="${LIVE_STACK_ENV:-$ROOT_DIR/config/system-stack.env}"
|
|
if [ -f "$STACK_ENV" ]; then
|
|
# shellcheck source=/dev/null
|
|
. "$STACK_ENV" || true
|
|
fi
|
|
|
|
INTERVAL="${LIVE_EDGE_WATCH_INTERVAL:-15}"
|
|
PORT="${PORT:-8001}"
|
|
|
|
log() {
|
|
printf '[live-edge-watch] %s\n' "$*"
|
|
}
|
|
|
|
positive_int() {
|
|
case "${1:-}" in
|
|
''|*[!0-9]*) return 1 ;;
|
|
*) [ "$1" -gt 0 ] ;;
|
|
esac
|
|
}
|
|
|
|
positive_int "$INTERVAL" || INTERVAL=15
|
|
|
|
while true; do
|
|
if [ "${ENABLE_LIVE_EDGE_PROXY:-1}" != "1" ]; then
|
|
sleep "$INTERVAL"
|
|
continue
|
|
fi
|
|
|
|
if ! systemctl is-active --quiet live-console.service 2>/dev/null; then
|
|
log "live-console.service inactive; starting"
|
|
systemctl start live-console.service >/dev/null 2>&1 || true
|
|
sleep 2
|
|
fi
|
|
|
|
if ! systemctl is-active --quiet live-edge.service 2>/dev/null; then
|
|
log "live-edge.service inactive; starting"
|
|
systemctl start live-edge.service >/dev/null 2>&1 || true
|
|
sleep "$INTERVAL"
|
|
continue
|
|
fi
|
|
|
|
if ! curl -fsS -m 4 "http://127.0.0.1/health" >/dev/null 2>&1; then
|
|
log "port 80 health failed; restarting live-edge.service for upstream :$PORT"
|
|
systemctl restart live-edge.service >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
sleep "$INTERVAL"
|
|
done
|