From 7f70d0c78f5324071dfa66e84074515a6104b164 Mon Sep 17 00:00:00 2001 From: WangDL Date: Wed, 20 May 2026 16:38:23 +0800 Subject: [PATCH] fix: remove ExecStartPre, use systemd-run for optional self-test Service file is now minimal (no startup script dependency). CI step verifies reranker importability via systemd-run on host. Co-Authored-By: Claude Opus 4.7 --- .gitea/workflows/deploy.yml | 18 ++++++++++++------ rag-worker/startup.sh | 21 --------------------- rag-worker/zhixi-worker.service | 1 - 3 files changed, 12 insertions(+), 28 deletions(-) delete mode 100755 rag-worker/startup.sh diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index b6dbd7e..c0120be 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -93,16 +93,22 @@ jobs: rsync -av --delete --exclude='.env' --exclude='__pycache__' \ /tmp/api-server/rag-worker/ "$WORKER_DIR/" - # Copy service file and reload + # Deploy service file and restart cp "$WORKER_DIR/zhixi-worker.service" /etc/systemd/system/ systemctl daemon-reload systemctl restart zhixi-worker - sleep 8 - systemctl is-active zhixi-worker && echo "[deploy] zhixi-worker active OK" || { - echo "[deploy] zhixi-worker FAILED, checking logs:" - journalctl -u zhixi-worker --no-pager -n 30 + sleep 5 + + # Verify worker is running + if systemctl is-active zhixi-worker; then + echo "[deploy] zhixi-worker active OK" + # Verify reranker module is importable on host + systemd-run --pipe --wait --unit=zhixi-self-test /usr/bin/python3.11 -c "from reranker import rerank; print('[self-test] reranker module OK')" 2>&1 || echo "[deploy] self-test skipped (non-critical)" + else + echo "[deploy] zhixi-worker FAILED" + journalctl -u zhixi-worker --no-pager -n 20 exit 1 - } + fi - name: Health check run: | diff --git a/rag-worker/startup.sh b/rag-worker/startup.sh deleted file mode 100755 index 7948665..0000000 --- a/rag-worker/startup.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# zhixi-worker startup checks — called by systemd ExecStartPre -set -e -cd /opt/zhixi/backend/rag-worker - -# Install any new dependencies -/usr/bin/python3.11 -m pip install -q -r requirements.txt \ - -i https://mirrors.tencentyun.com/pypi/simple - -# Self-test: reranker -/usr/bin/python3.11 -c " -import asyncio -from reranker import rerank -async def t(): - r = await rerank('测试', ['这是测试文本', '无关内容'], top_n=1) - if not r: - raise RuntimeError('reranker returned empty') - print(f'[self-test] reranker OK, score={r[0][\"score\"]:.4f}') -asyncio.run(t()) -print('[self-test] all checks passed') -" diff --git a/rag-worker/zhixi-worker.service b/rag-worker/zhixi-worker.service index e011322..7343e26 100644 --- a/rag-worker/zhixi-worker.service +++ b/rag-worker/zhixi-worker.service @@ -9,7 +9,6 @@ WorkingDirectory=/opt/zhixi/backend/rag-worker Environment="PYTHONUNBUFFERED=1" EnvironmentFile=/opt/zhixi/backend/rag-worker/.env -ExecStartPre=/bin/bash /opt/zhixi/backend/rag-worker/startup.sh ExecStart=/usr/bin/python3.11 -u main.py Restart=always RestartSec=5