fix: remove ExecStartPre, use systemd-run for optional self-test
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 8s

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 <noreply@anthropic.com>
This commit is contained in:
WangDL 2026-05-20 16:38:23 +08:00
parent 88a2162b62
commit 7f70d0c78f
3 changed files with 12 additions and 28 deletions

View File

@ -93,16 +93,22 @@ jobs:
rsync -av --delete --exclude='.env' --exclude='__pycache__' \ rsync -av --delete --exclude='.env' --exclude='__pycache__' \
/tmp/api-server/rag-worker/ "$WORKER_DIR/" /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/ cp "$WORKER_DIR/zhixi-worker.service" /etc/systemd/system/
systemctl daemon-reload systemctl daemon-reload
systemctl restart zhixi-worker systemctl restart zhixi-worker
sleep 8 sleep 5
systemctl is-active zhixi-worker && echo "[deploy] zhixi-worker active OK" || {
echo "[deploy] zhixi-worker FAILED, checking logs:" # Verify worker is running
journalctl -u zhixi-worker --no-pager -n 30 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 exit 1
} fi
- name: Health check - name: Health check
run: | run: |

View File

@ -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')
"

View File

@ -9,7 +9,6 @@ WorkingDirectory=/opt/zhixi/backend/rag-worker
Environment="PYTHONUNBUFFERED=1" Environment="PYTHONUNBUFFERED=1"
EnvironmentFile=/opt/zhixi/backend/rag-worker/.env 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 ExecStart=/usr/bin/python3.11 -u main.py
Restart=always Restart=always
RestartSec=5 RestartSec=5