This commit is contained in:
eric
2026-03-29 04:12:59 -05:00
parent e20c1a0b0b
commit 3dc82e1158
2 changed files with 14 additions and 6 deletions

View File

@@ -256,6 +256,9 @@ Restart=always
RestartSec=5 RestartSec=5
# 避免构建/依赖短暂失败时触发 systemd 默认「5 次/10s」后永久停跑(表现为 live-edge 502、:8001 无监听) # 避免构建/依赖短暂失败时触发 systemd 默认「5 次/10s」后永久停跑(表现为 live-edge 502、:8001 无监听)
StartLimitIntervalSec=0 StartLimitIntervalSec=0
# 首次 npm build / 冷启动较慢;过小会导致主进程在 listen 前被 SIGTERM
TimeoutStartSec=300
TimeoutStopSec=30
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

17
web.py
View File

@@ -342,12 +342,17 @@ async def lifespan(app: FastAPI):
except Exception: except Exception:
# PM2/Shell 异常时不阻塞整站启动(否则反代持续 502) # PM2/Shell 异常时不阻塞整站启动(否则反代持续 502)
pass pass
try:
ok, msg = await asyncio.to_thread(ensure_scrcpy_jar, BASE_DIR) # scrcpy-server 下载可走外网重试,勿阻塞启动;否则 systemd 默认 TimeoutStartSec≈90s 会杀进程,:8001 永不起
if not ok: async def _bootstrap_scrcpy() -> None:
print(f"[web] scrcpy-server: {msg}", file=sys.stderr) try:
except Exception as exc: ok, msg = await asyncio.to_thread(ensure_scrcpy_jar, BASE_DIR)
print(f"[web] scrcpy-server bootstrap: {exc}", file=sys.stderr) if not ok:
print(f"[web] scrcpy-server: {msg}", file=sys.stderr)
except Exception as exc:
print(f"[web] scrcpy-server bootstrap: {exc}", file=sys.stderr)
asyncio.create_task(_bootstrap_scrcpy())
yield yield