-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathgunicorn_conf.py
More file actions
51 lines (44 loc) · 2.3 KB
/
gunicorn_conf.py
File metadata and controls
51 lines (44 loc) · 2.3 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
import os
import json
import sqlalchemy
from pathlib import Path
from app.core.logging_config import LOGGING_CONFIG
from app.core.config import settings
# Gunicorn config variables
loglevel = os.environ.get("LOG_LEVEL", "info")
workers = int(os.environ.get("GUNICORN_WORKERS", "4"))
bind = os.environ.get("GUNICORN_BIND", "0.0.0.0:8080")
worker_class = os.environ.get("GUNICORN_WORKER_CLASS", "uvicorn.workers.UvicornWorker")
timeout = int(os.environ.get("GUNICORN_TIMEOUT", "120")) # Allow 2 mins for AI tasks
accesslog = "-" # Direct access logs to stdout
errorlog = "-" # Direct error logs to stdout
# Use our custom JSON logging config
logconfig_dict = LOGGING_CONFIG
# --- Load SSL settings from DB for Gunicorn ---
keyfile = None
certfile = None
try:
# Construct synchronous DB URL from bootstrap settings
if settings.DATABASE_URL.startswith("sqlite+aiosqlite"):
db_path = settings.DATABASE_URL.split("///")[-1]
if Path(db_path).exists():
sync_db_url = f"sqlite:///{db_path}"
engine = sqlalchemy.create_engine(sync_db_url)
with engine.connect() as connection:
result = connection.execute(sqlalchemy.text("SELECT settings_data FROM app_settings WHERE id = 1")).fetchone()
if result and result[0]:
db_settings = json.loads(result[0])
keyfile_path = db_settings.get("ssl_keyfile")
certfile_path = db_settings.get("ssl_certfile")
if keyfile_path and certfile_path:
if Path(keyfile_path).is_file() and Path(certfile_path).is_file():
keyfile = keyfile_path
certfile = certfile_path
print(f"[INFO] Gunicorn starting with HTTPS. Cert: {certfile}")
else:
if not Path(keyfile_path).is_file():
print(f"[WARNING] SSL key file not found at '{keyfile_path}'. HTTPS disabled.")
if not Path(certfile_path).is_file():
print(f"[WARNING] SSL cert file not found at '{certfile_path}'. HTTPS disabled.")
except Exception as e:
print(f"[INFO] Could not load SSL settings from DB (this is normal on first run). Reason: {e}")