From 9c5a2688f274d9a5206b5473ed4f27f179a8ec46 Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 10 Oct 2026 23:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=89=8D=E5=85=88=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E7=A8=8B=E5=BA=8F=E8=83=BD=E5=AF=BC=E5=85=A5=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=BB=B6=E9=95=BF=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- deploy/manage.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/deploy/manage.sh b/deploy/manage.sh index 4e1d543..40bd759 100644 --- a/deploy/manage.sh +++ b/deploy/manage.sh @@ -200,16 +200,27 @@ fix_permissions() { wait_until_ready() { local ready=0 local _i - for _i in 1 2 3 4 5 6 7 8 9 10; do - if curl -fsS "http://127.0.0.1:${BIND_PORT}/health" >/dev/null; then + echo "等待服务监听 ${BIND_PORT} ..." + for ((_i = 1; _i <= 40; _i++)); do + if curl -fsS "http://127.0.0.1:${BIND_PORT}/health" >/dev/null 2>&1; then ready=1 break fi sleep 1 done if [[ "${ready}" -ne 1 ]]; then - echo "服务未在 10 秒内就绪。最近日志:" >&2 - journalctl -u "${SERVICE_NAME}.service" -n 50 --no-pager >&2 || true + echo "服务未在 40 秒内就绪。状态和最近日志:" >&2 + systemctl status "${SERVICE_NAME}.service" --no-pager >&2 || true + journalctl -u "${SERVICE_NAME}.service" -n 80 --no-pager >&2 || true + return 1 + fi + echo "健康检查通过:http://127.0.0.1:${BIND_PORT}/health" +} + +verify_app() { + log "检查程序能否启动" + if ! /usr/sbin/runuser -u "${APP_USER}" -- bash -c "cd '${INSTALL_ROOT}' && exec '${INSTALL_ROOT}/.venv/bin/python' -c 'import app.main'"; then + echo "程序导入失败,没有重启服务。请把上面的报错发出来。" >&2 return 1 fi } @@ -223,9 +234,10 @@ cmd_deploy() { install_python_deps fix_permissions write_service + verify_app || return 1 systemctl enable "${SERVICE_NAME}.service" systemctl restart "${SERVICE_NAME}.service" - wait_until_ready + wait_until_ready || return 1 log "部署完成" echo "监听地址:${BIND_HOST}:${BIND_PORT}" echo "健康检查:curl http://127.0.0.1:${BIND_PORT}/health" @@ -257,8 +269,9 @@ cmd_update() { install_python_deps fix_permissions write_service + verify_app || return 1 systemctl restart "${SERVICE_NAME}.service" - wait_until_ready + wait_until_ready || return 1 log "更新完成,配置和数据库已保留" }