Files
kami_apple_exchage/backend/run.py
danial 48cdcb6140 feat: Add deployment scripts and configuration for Apple Gift Card Exchange Platform
- Create README.md for deployment instructions including environment requirements and setup steps.
- Implement deploy.sh script for automated deployment of development and production environments.
- Add combined Docker Compose configuration for frontend and backend services.
- Include Redis configuration file for optimized memory management and persistence.
- Update frontend Dockerfile to handle Next.js asset paths and static files.
- Remove obsolete deployment files and configurations from frontend directory.
2025-09-11 17:57:18 +08:00

110 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
Gunicorn配置文件
用于生产环境的FastAPI应用启动
"""
import os
import multiprocessing
from pathlib import Path
# 基础配置
bind = "0.0.0.0:8000"
workers = int(os.environ.get("WORKERS", multiprocessing.cpu_count() * 2 + 1))
worker_class = "uvicorn.workers.UvicornWorker"
worker_connections = 1000
max_requests = 1000
max_requests_jitter = 100
timeout = 30
keepalive = 2
# 日志配置
accesslog = "-"
errorlog = "-"
loglevel = "info"
# 安全配置
limit_request_line = 4096
limit_request_fields = 100
limit_request_field_size = 8190
# 进程管理
preload_app = True
pidfile = "/tmp/gunicorn.pid"
# 工作进程重启时的临时目录
temp_dir = "/tmp"
# 工作进程重启时保留的文件描述符数量
worker_tmp_dir = "/dev/shm"
# 环境变量传递
raw_env = [
f"ENVIRONMENT={os.environ.get('ENVIRONMENT', 'production')}",
f"DATABASE_URL={os.environ.get('DATABASE_URL', '')}",
f"REDIS_URL={os.environ.get('REDIS_URL', '')}",
f"CELERY_BROKER_URL={os.environ.get('CELERY_BROKER_URL', '')}",
f"CELERY_RESULT_BACKEND={os.environ.get('CELERY_RESULT_BACKEND', '')}",
]
# 重启策略
graceful_timeout = 30
reload = False
# 统计和监控
statsd_host = None
statsd_prefix = ""
# 工作进程启动时的钩子函数
def on_starting(server):
"""工作进程启动前的钩子函数"""
pass
def on_reload(server):
"""重载时的钩子函数"""
pass
def when_ready(server):
"""服务器准备就绪时的钩子函数"""
pass
def on_exit(server):
"""服务器退出时的钩子函数"""
pass
# 工作进程相关的钩子函数
def pre_fork(server, worker):
"""工作进程fork前的钩子函数"""
pass
def post_fork(server, worker):
"""工作进程fork后的钩子函数"""
pass
def post_worker_init(worker):
"""工作进程初始化后的钩子函数"""
pass
def worker_int(worker):
"""工作进程收到中断信号时的钩子函数"""
pass
def worker_abort(worker):
"""工作进程异常终止时的钩子函数"""
pass
def child_exit(server, worker):
"""子进程退出时的钩子函数"""
pass
def pre_exec(server):
"""工作进程执行前的钩子函数"""
pass
def pre_request(worker, req):
"""请求处理前的钩子函数"""
pass
def post_request(worker, req, environ, resp):
"""请求处理后的钩子函数"""
pass