Make Gunicorn respect config.json settings

- Updated gunicorn.conf.py to read host/port from config.json
- Added gunicorn section to config.json for server settings
- Created start_gunicorn.py as alternative launcher
- Updated config.json with server settings (127.0.0.1:6969)
- Updated documentation with new startup options
This commit is contained in:
2025-09-20 20:25:36 +01:00
parent 4b31d3b9e0
commit 720b89a296
4 changed files with 95 additions and 15 deletions

View File

@@ -1,21 +1,42 @@
# Gunicorn configuration file for ircquotes
import multiprocessing
import json
import os
# Server socket
bind = "0.0.0.0:5050"
# Load configuration from config.json
def load_app_config():
config_file = os.path.join(os.path.dirname(__file__), 'config.json')
try:
with open(config_file, 'r') as f:
return json.load(f)
except:
# Fallback to defaults if config.json not found
return {
"app": {"host": "0.0.0.0", "port": 5050}
}
app_config = load_app_config()
# Server socket - use config.json values
host = app_config.get('app', {}).get('host', '0.0.0.0')
port = app_config.get('app', {}).get('port', 5050)
bind = f"{host}:{port}"
backlog = 2048
# Worker processes
workers = multiprocessing.cpu_count() * 2 + 1
# Worker processes - use config.json values
workers = app_config.get('gunicorn', {}).get('workers', multiprocessing.cpu_count() * 2 + 1)
worker_class = "sync"
worker_connections = 1000
timeout = 30
keepalive = 5
timeout = app_config.get('gunicorn', {}).get('timeout', 30)
keepalive = app_config.get('gunicorn', {}).get('keepalive', 5)
# Restart workers after this many requests, to help prevent memory leaks
max_requests = 1000
max_requests = app_config.get('gunicorn', {}).get('max_requests', 1000)
max_requests_jitter = 100
# Preload app for better performance
preload_app = app_config.get('gunicorn', {}).get('preload', True)
# Logging
accesslog = "-" # Log to stdout
errorlog = "-" # Log to stderr