-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgunicorn.conf.py
More file actions
66 lines (54 loc) · 2.33 KB
/
gunicorn.conf.py
File metadata and controls
66 lines (54 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Gunicorn configuration for Open Hardware Manager
# This configuration is optimized for production deployment
import multiprocessing
import os
# Server socket
# Support PORT env var (Cloud Run) and API_PORT (backward compatibility)
# Cloud Run sets PORT=8080, so we prioritize PORT over API_PORT
port_env = os.getenv("PORT")
api_port_env = os.getenv("API_PORT")
port = port_env or api_port_env or "8001"
# Ensure port is a string for the bind address
port = str(port) if port else "8001"
bind = f"0.0.0.0:{port}"
# Debug output (will appear in Gunicorn startup logs)
print(f"[Gunicorn Config] PORT env var: {port_env}")
print(f"[Gunicorn Config] API_PORT env var: {api_port_env}")
print(f"[Gunicorn Config] Using port: {port}")
print(f"[Gunicorn Config] Binding to: {bind}")
backlog = 2048
# Worker processes
workers = int(os.getenv("GUNICORN_WORKERS", multiprocessing.cpu_count() * 2 + 1))
# Use uvicorn workers for async FastAPI application
worker_class = os.getenv("GUNICORN_WORKER_CLASS", "uvicorn.workers.UvicornWorker")
worker_connections = int(os.getenv("GUNICORN_WORKER_CONNECTIONS", "1000"))
max_requests = int(os.getenv("GUNICORN_MAX_REQUESTS", "1000"))
max_requests_jitter = int(os.getenv("GUNICORN_MAX_REQUESTS_JITTER", "100"))
# Timeout settings
timeout = int(os.getenv("GUNICORN_TIMEOUT", "120"))
keepalive = int(os.getenv("GUNICORN_KEEPALIVE", "5"))
# Logging
accesslog = os.getenv("GUNICORN_ACCESS_LOG", "-")
errorlog = os.getenv("GUNICORN_ERROR_LOG", "-")
loglevel = os.getenv("GUNICORN_LOG_LEVEL", "info")
access_log_format = os.getenv(
"GUNICORN_ACCESS_LOG_FORMAT",
'%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(D)s',
)
# Process naming
proc_name = "open-hardware-manager"
# Server mechanics
daemon = False
pidfile = "/tmp/gunicorn.pid"
# Note: user/group are set in Dockerfile (USER ohm), so we don't need to set them here
# If we're already running as the correct user, Gunicorn will skip privilege dropping
# user = 'ohm' # Commented out - already running as ohm user in container
# group = 'ohm' # Commented out - already running as ohm user in container
tmp_upload_dir = None
# SSL (if needed)
# keyfile = '/path/to/keyfile'
# certfile = '/path/to/certfile'
# Preload application for better performance
preload_app = True
# Additional worker settings
keepalive_timeout = int(os.getenv("GUNICORN_KEEPALIVE_TIMEOUT", "5"))