Files
Django/deploy/gunicorn-warmup.sh

17 lines
724 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 每 2 分钟 ping 一次 Gunicorn避免 worker/数据库连接空闲后「第一下卡」
# 安装: cp deploy/gunicorn-warmup.cron /etc/cron.d/gunicorn-warmup && chmod 644 /etc/cron.d/gunicorn-warmup
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
cd "$DJANGO_DIR"
# 6 个 worker 各打一次,保持连接池温热
for _ in 1 2 3 4 5 6; do
curl -s -o /dev/null --max-time 3 http://127.0.0.1:8001/ &
done
wait
# 顺带测一条需连库的轻量配置接口(无需 token 的会 401/404但会走 Django+MySQL
curl -s -o /dev/null --max-time 5 -X POST http://127.0.0.1:8001/hqhd/peizhi/qdpzhq \
-H 'Content-Type: application/json' -d '{}' 2>/dev/null || true