This commit is contained in:
eric
2026-03-28 13:27:53 -05:00
parent d34ecab19c
commit 8053c4cb6d
48 changed files with 3527 additions and 1433 deletions

View File

@@ -33,4 +33,5 @@ install_netdata
prepare_homepage
prepare_filebrowser
run_hardware_probe
install_live_edge_proxy
print_summary "hub"

View File

@@ -77,7 +77,7 @@ load_env() {
HOSTNAME_ALIAS="${HOSTNAME_ALIAS:-live}"
PORT="${PORT:-8001}"
WEBTTY_PORT="${WEBTTY_PORT:-7681}"
HOMEPAGE_PORT="${HOMEPAGE_PORT:-80}"
HOMEPAGE_PORT="${HOMEPAGE_PORT:-3080}"
FILEBROWSER_PORT="${FILEBROWSER_PORT:-8082}"
NETDATA_PORT="${NETDATA_PORT:-19999}"
SRS_HTTP_PORT="${SRS_HTTP_PORT:-8080}"
@@ -98,6 +98,7 @@ load_env() {
ANDROID_PANEL_PORT="${ANDROID_PANEL_PORT:-5000}"
ANDROID_PANEL_DIR="${ANDROID_PANEL_DIR:-/opt/live-modules/web-scrcpy}"
ANDROID_PANEL_VIDEO_BIT_RATE="${ANDROID_PANEL_VIDEO_BIT_RATE:-1024000}"
ENABLE_LIVE_EDGE_PROXY="${ENABLE_LIVE_EDGE_PROXY:-1}"
}
ensure_live_user() {
@@ -548,12 +549,21 @@ PY
render_homepage_services() {
local target="$ROOT_DIR/services/homepage/config/services.yaml"
local primary_console
if [ "${ENABLE_LIVE_EDGE_PROXY:-1}" = "1" ]; then
primary_console="http://${HOSTNAME_ALIAS}.local"
else
primary_console="http://${HOSTNAME_ALIAS}.local:${PORT}"
fi
log "Rendering Homepage service links"
cat >"$target" <<YAML
- Infrastructure:
- Hub Console:
- Live Console:
href: ${primary_console}
description: Product control center (Caddy :80 when edge proxy enabled)
- Hub Console (direct port):
href: http://${HOSTNAME_ALIAS}.local:${PORT}
description: Chinese-first control plane and modular service center
description: Direct access to FastAPI port
YAML
if [ "${ENABLE_WEBTTY:-1}" = "1" ]; then
cat >>"$target" <<YAML
@@ -723,13 +733,98 @@ run_hardware_probe() {
as_live ". .venv/bin/activate && python scripts/hardware_probe.py --write"
}
install_live_edge_proxy() {
if [ "${ENABLE_LIVE_EDGE_PROXY:-1}" != "1" ]; then
return 0
fi
log "Installing edge proxy (Caddy :80 → control plane :${PORT})"
mkdir -p /opt/live/generated
local lp="$ROOT_DIR/live-platform"
if [ -f "$lp/tools/render_caddyfile.py" ]; then
python3 "$lp/tools/render_caddyfile.py" "$HOSTNAME_ALIAS" "$PORT" /opt/live/generated/Caddyfile
else
log "WARN: live-platform/tools/render_caddyfile.py missing, skip Caddyfile"
return 0
fi
# 若 Homepage 仍占 80下线并改绑 3080 后重启
if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -qx live-homepage; then
if docker ps --format '{{.Names}} {{.Ports}}' 2>/dev/null | grep -E 'live-homepage' | grep -qE '0\.0\.0\.0:80->|:::80->'; then
log "Rebinding Homepage from host :80 → :3080 (free port for Caddy)"
export HOMEPAGE_PORT=3080
if [ -f "$ROOT_DIR/config/system-stack.env" ] && grep -q '^HOMEPAGE_PORT=80' "$ROOT_DIR/config/system-stack.env"; then
sed -i 's/^HOMEPAGE_PORT=80$/HOMEPAGE_PORT=3080/' "$ROOT_DIR/config/system-stack.env" || true
fi
compose_run "$ROOT_DIR/services/homepage/docker-compose.yml" down >/dev/null 2>&1 || true
render_homepage_services
compose_run "$ROOT_DIR/services/homepage/docker-compose.yml" up -d || true
fi
fi
if ! command -v caddy >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq caddy || true
fi
fi
if ! command -v caddy >/dev/null 2>&1; then
log "Installing Caddy from GitHub release (apt had no caddy)"
local arch raw
raw="$(uname -m)"
case "$raw" in
aarch64|arm64) arch="arm64" ;;
x86_64|amd64) arch="amd64" ;;
armv7l|armv6l) arch="armv7" ;;
*)
log "WARN: unknown arch $raw — install caddy manually"
return 0
;;
esac
local ver="2.8.4"
local tmp="/tmp/caddy-${ver}-linux-${arch}.tar.gz"
curl -fsSL "https://github.com/caddyserver/caddy/releases/download/v${ver}/caddy_${ver}_linux_${arch}.tar.gz" -o "$tmp"
tar -xzf "$tmp" -C /tmp caddy
install -m0755 /tmp/caddy /usr/local/bin/caddy
rm -f "$tmp" /tmp/caddy
fi
systemctl stop caddy >/dev/null 2>&1 || true
systemctl disable caddy >/dev/null 2>&1 || true
local caddy_bin
caddy_bin="$(command -v caddy || true)"
[ -n "$caddy_bin" ] || caddy_bin="/usr/local/bin/caddy"
cat >/etc/systemd/system/live-edge.service <<UNIT
[Unit]
Description=Live edge proxy (http://${HOSTNAME_ALIAS}.local -> :${PORT})
After=network-online.target live-console.service
Wants=network-online.target
Requires=live-console.service
[Service]
Type=simple
ExecStart=$caddy_bin run --config /opt/live/generated/Caddyfile --adapter caddyfile
Restart=on-failure
RestartSec=4
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable --now live-edge.service
log "Edge proxy live-edge.service enabled (http://${HOSTNAME_ALIAS}.local)"
}
print_summary() {
local profile="$1"
cat <<TXT
Profile: $profile
Control Plane: http://${HOSTNAME_ALIAS}.local:${PORT}
Homepage: http://${HOSTNAME_ALIAS}.local${HOMEPAGE_PORT:+:${HOMEPAGE_PORT}}
Primary URL: http://${HOSTNAME_ALIAS}.local (Caddy → :${PORT} when live-edge is running)
Control Plane (direct): http://${HOSTNAME_ALIAS}.local:${PORT}
Homepage: http://${HOSTNAME_ALIAS}.local:${HOMEPAGE_PORT}
WebTTY: http://${HOSTNAME_ALIAS}.local:${WEBTTY_PORT}
TXT
}

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# 仅重装 Caddy 边缘反代http://live.local → :PORT需已存在 live-console
set -euo pipefail
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
INSTALL_TAG="edge"
. "$SELF_DIR/lib/common.sh"
ensure_root "$@"
load_env
install_live_edge_proxy