34 lines
1.4 KiB
Desktop File
34 lines
1.4 KiB
Desktop File
# zcbot 蓝绿双实例模板 unit(RUN.md §无感更新 B 档)。
|
|
# 安装:sudo cp deploy/zcbot@.service /etc/systemd/system/ && sudo systemctl daemon-reload
|
|
# 实例:zcbot@blue(port 8765)/ zcbot@green(port 8766),端口与实例名由
|
|
# deploy/instances/<实例>.env 注入(ZCBOT_PORT / ZCBOT_INSTANCE)。
|
|
# nginx upstream 在两实例间切流量,部署走 deploy/update_bluegreen.sh。
|
|
[Unit]
|
|
Description=zcbot web (FastAPI/uvicorn) - instance %i
|
|
After=network-online.target postgresql.service
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=zcbot
|
|
WorkingDirectory=/opt/zcbot
|
|
# 先装 .env(业务配置),再装实例 env(ZCBOT_PORT/ZCBOT_INSTANCE,后装覆盖前者同名项)
|
|
EnvironmentFile=/opt/zcbot/.env
|
|
EnvironmentFile=/opt/zcbot/deploy/instances/%i.env
|
|
# 只绑 127.0.0.1:对外统一走 nginx,实例端口不直接暴露
|
|
ExecStart=/opt/zcbot/.venv/bin/python main.py web --host 127.0.0.1 --port ${ZCBOT_PORT}
|
|
Restart=on-failure
|
|
RestartSec=2
|
|
KillSignal=SIGTERM
|
|
# ★ 优雅 drain:SIGTERM 后先拒新 run(503)、等在跑的 run 收尾(config/agent.yaml
|
|
# `shutdown` 段:drain_timeout 30s + cancel_grace 15s)。TimeoutStopSec 必须 >
|
|
# drain_timeout + cancel_grace + 余量(sandbox 容器清扫 + uvicorn graceful 5s),
|
|
# 否则 systemd 中途 SIGKILL 把 drain 砍掉。改 agent.yaml 那两个数值时这里跟着调。
|
|
TimeoutStopSec=90
|
|
KillMode=mixed
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|