[Unit] Description=ZhiXi RAG Worker After=network.target [Service] Type=simple User=root WorkingDirectory=/opt/zhixi/backend/rag-worker Environment="PYTHONUNBUFFERED=1" EnvironmentFile=/opt/zhixi/backend/rag-worker/.env # Install deps and self-test before starting main loop ExecStartPre=/usr/bin/python3.11 -m pip install -q -r /opt/zhixi/backend/rag-worker/requirements.txt -i https://mirrors.tencentyun.com/pypi/simple ExecStartPre=/usr/bin/python3.11 -c " import asyncio, sys 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') " ExecStart=/usr/bin/python3.11 -u main.py Restart=always RestartSec=5 [Install] WantedBy=multi-user.target