114 lines
4.1 KiB
Bash
Executable File
114 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# 排查「live.local refused to connect」:多为 :80 无进程、服务未起、或跨机 mDNS/防火墙。
|
||
# 在设备本机执行: sudo bash scripts/linux/probe_live_access.sh
|
||
set +e
|
||
set -u
|
||
set -o pipefail
|
||
|
||
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||
INSTALL_TAG="probe"
|
||
# shellcheck source=scripts/linux/lib/common.sh
|
||
. "$SELF_DIR/lib/common.sh"
|
||
|
||
load_env
|
||
MDNS_HOST="${HOSTNAME_ALIAS:-live}.local"
|
||
|
||
echo "=== Probe: refused to connect (no listener / firewall / wrong host) ==="
|
||
echo "Note: 502 = reverse proxy up but upstream dead; refused = nothing accepting TCP."
|
||
echo ""
|
||
|
||
echo "--- Host / IP ---"
|
||
echo "hostname: $(hostname 2>/dev/null)"
|
||
echo "mdns host: $MDNS_HOST"
|
||
LAN_IP=""
|
||
LAN_IP="$(detect_preferred_lan_ip || true)"
|
||
echo "guess LAN IP: ${LAN_IP:-unknown}"
|
||
echo ""
|
||
|
||
echo "--- systemd (need root for full status) ---"
|
||
for u in live-console live-edge; do
|
||
if systemctl is-active "$u.service" >/dev/null 2>&1; then
|
||
echo "$u.service: active"
|
||
else
|
||
echo "$u.service: INACTIVE — run: sudo systemctl status $u.service"
|
||
fi
|
||
done
|
||
echo ""
|
||
|
||
echo "--- TCP listeners :80 and :${PORT} ---"
|
||
if command -v ss >/dev/null 2>&1; then
|
||
ss -tlnp 2>/dev/null | grep -E ":80\\b|:${PORT}\\b" || echo "(no LISTEN on :80 or :${PORT})"
|
||
else
|
||
netstat -tlnp 2>/dev/null | grep -E ":80\\b|:${PORT}\\b" || true
|
||
fi
|
||
echo ""
|
||
|
||
echo "--- Loopback checks ---"
|
||
if curl -sf -m 5 "http://127.0.0.1:${PORT}/health" >/dev/null; then
|
||
echo "OK http://127.0.0.1:${PORT}/health"
|
||
else
|
||
echo "FAIL http://127.0.0.1:${PORT}/health → fix live-console first: journalctl -u live-console.service -n 60"
|
||
fi
|
||
|
||
code="$(curl -sS -m 5 -o /dev/null -w '%{http_code}' "http://127.0.0.1/" 2>/dev/null)"
|
||
if [ "$code" = "000" ] || [ -z "$code" ]; then
|
||
echo "FAIL http://127.0.0.1/ (port 80) — live-edge/Caddy not listening or connection refused"
|
||
echo " Try: sudo bash scripts/linux/reinstall_live_edge.sh && sudo systemctl restart live-edge.service"
|
||
elif [ "$code" = "502" ]; then
|
||
echo "WARN http://127.0.0.1/ → 502 — Caddy up but upstream :${PORT} down; restart live-console"
|
||
else
|
||
echo "OK http://127.0.0.1/ → HTTP $code"
|
||
fi
|
||
echo ""
|
||
|
||
echo "--- mDNS / LAN acceptance ---"
|
||
if getent hosts "$MDNS_HOST" >/dev/null 2>&1; then
|
||
echo "OK getent hosts $MDNS_HOST"
|
||
else
|
||
echo "FAIL getent hosts $MDNS_HOST → check avahi-daemon / libnss-mdns"
|
||
fi
|
||
|
||
deploy_json="$(curl -fsS -m 10 "http://127.0.0.1:${PORT}/deploy/check" 2>/dev/null || true)"
|
||
if [ -n "$deploy_json" ]; then
|
||
DEPLOY_JSON="$deploy_json" python3 - <<'PY'
|
||
import json
|
||
import os
|
||
|
||
raw = os.environ.get("DEPLOY_JSON", "").strip()
|
||
if not raw:
|
||
raise SystemExit(0)
|
||
data = json.loads(raw)
|
||
status = "READY" if data.get("ready") else "DEGRADED"
|
||
print(f"deployment: {status} ({data.get('pass_count', 0)}/{data.get('total_count', 0)})")
|
||
for item in data.get("failing_checks") or []:
|
||
label = item.get("label") or item.get("id") or "check"
|
||
detail = item.get("detail") or item.get("error") or ""
|
||
print(f"- FAIL {label}: {detail}")
|
||
for hint in data.get("hints") or []:
|
||
print(f"- hint: {hint}")
|
||
PY
|
||
else
|
||
echo "deploy/check unavailable on :${PORT}"
|
||
fi
|
||
echo ""
|
||
|
||
echo "--- From your phone/PC browser ---"
|
||
echo "1) Same Wi‑Fi/LAN as this box."
|
||
echo "2) Try: http://${LAN_IP}:${PORT}/ (direct control plane, bypasses :80 and mDNS)"
|
||
echo "3) Try: http://${MDNS_HOST}/ (edge proxy) or http://${MDNS_HOST}:${PORT}/ (direct API)."
|
||
echo "4) live.local needs mDNS (Android often OK; Windows may need Bonjour or use IP)."
|
||
echo "5) If OK on IP but not live.local: Avahi on this host — systemctl status avahi-daemon"
|
||
echo ""
|
||
|
||
if ! systemctl is-active live-console.service >/dev/null 2>&1; then
|
||
echo "=== Fix live-console (your case: edge OK, :${PORT} down) ==="
|
||
echo "sudo systemctl reset-failed live-console.service 2>/dev/null || true"
|
||
echo "sudo systemctl enable --now live-console.service"
|
||
echo "sleep 3 && curl -sf http://127.0.0.1:${PORT}/health && echo OK || echo still failing — logs:"
|
||
echo "sudo journalctl -u live-console.service -n 80 --no-pager"
|
||
echo ""
|
||
echo "After git pull / code update, prefer: sudo bash upgrade-live.sh"
|
||
echo "Only systemd unit changed? sudo bash refresh-live-unit.sh"
|
||
echo ""
|
||
fi
|