"feat: Integrate Gunicorn for better process management in backend/app"
This commit is contained in:
Binary file not shown.
75
backend/app/gunicorn.conf.py
Normal file
75
backend/app/gunicorn.conf.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Gunicorn-Konfiguration für MYP Platform Produktionsumgebung
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import multiprocessing
|
||||||
|
|
||||||
|
# Server Socket
|
||||||
|
bind = "0.0.0.0:8000"
|
||||||
|
backlog = 2048
|
||||||
|
|
||||||
|
# Worker Prozesse
|
||||||
|
workers = min(4, multiprocessing.cpu_count() * 2 + 1)
|
||||||
|
worker_class = "gthread"
|
||||||
|
worker_connections = 1000
|
||||||
|
threads = 2
|
||||||
|
|
||||||
|
# Timeouts
|
||||||
|
timeout = 30
|
||||||
|
keepalive = 5
|
||||||
|
graceful_timeout = 30
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
accesslog = os.path.join(os.path.dirname(__file__), "logs", "app", "gunicorn_access.log")
|
||||||
|
errorlog = os.path.join(os.path.dirname(__file__), "logs", "app", "gunicorn_error.log")
|
||||||
|
loglevel = "info"
|
||||||
|
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(D)s'
|
||||||
|
|
||||||
|
# Prozess-Namen
|
||||||
|
proc_name = "myp-platform"
|
||||||
|
|
||||||
|
# SSL/TLS (falls erforderlich)
|
||||||
|
# keyfile = "certs/myp.key"
|
||||||
|
# certfile = "certs/myp.crt"
|
||||||
|
|
||||||
|
# Performance
|
||||||
|
preload_app = True
|
||||||
|
max_requests = 1000
|
||||||
|
max_requests_jitter = 100
|
||||||
|
|
||||||
|
# Worker-Speicher-Management
|
||||||
|
worker_tmp_dir = "/dev/shm"
|
||||||
|
|
||||||
|
# Sicherheit
|
||||||
|
forwarded_allow_ips = "*"
|
||||||
|
secure_scheme_headers = {
|
||||||
|
'X-FORWARDED-PROTOCOL': 'ssl',
|
||||||
|
'X-FORWARDED-PROTO': 'https',
|
||||||
|
'X-FORWARDED-SSL': 'on'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Startup/Shutdown Hooks
|
||||||
|
def on_starting(server):
|
||||||
|
"""Wird beim Server-Start ausgeführt"""
|
||||||
|
server.log.info("🚀 MYP Platform wird gestartet...")
|
||||||
|
|
||||||
|
def when_ready(server):
|
||||||
|
"""Wird ausgeführt wenn Server bereit ist"""
|
||||||
|
server.log.info("✅ MYP Platform ist bereit und wartet auf Anfragen")
|
||||||
|
|
||||||
|
def worker_init(worker):
|
||||||
|
"""Wird für jeden Worker beim Start ausgeführt"""
|
||||||
|
worker.log.info(f"👷 Worker {worker.pid} initialisiert")
|
||||||
|
|
||||||
|
def on_exit(server):
|
||||||
|
"""Wird beim Server-Shutdown ausgeführt"""
|
||||||
|
server.log.info("🛑 MYP Platform wird heruntergefahren...")
|
||||||
|
|
||||||
|
# Umgebungsvariablen
|
||||||
|
raw_env = [
|
||||||
|
'MYP_ENVIRONMENT=production',
|
||||||
|
'FLASK_ENV=production',
|
||||||
|
'PYTHONPATH=/opt/myp-platform'
|
||||||
|
]
|
52
backend/app/myp-platform.service
Normal file
52
backend/app/myp-platform.service
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=MYP Platform - Mercedes-Benz 3D Druck Management System
|
||||||
|
Documentation=https://github.com/mercedes-benz/myp-platform
|
||||||
|
After=network.target postgresql.service mysql.service
|
||||||
|
Wants=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
User=myp
|
||||||
|
Group=myp
|
||||||
|
WorkingDirectory=/opt/myp-platform/backend/app
|
||||||
|
Environment=PATH=/opt/myp-platform/venv/bin
|
||||||
|
Environment=MYP_ENVIRONMENT=production
|
||||||
|
Environment=FLASK_ENV=production
|
||||||
|
Environment=PYTHONPATH=/opt/myp-platform/backend/app
|
||||||
|
|
||||||
|
# Gunicorn mit Konfigurationsdatei starten
|
||||||
|
ExecStart=/opt/myp-platform/venv/bin/gunicorn app:app -c gunicorn.conf.py
|
||||||
|
ExecReload=/bin/kill -s HUP $MAINPID
|
||||||
|
|
||||||
|
# Restart-Policy
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
StartLimitInterval=60
|
||||||
|
StartLimitBurst=3
|
||||||
|
|
||||||
|
# Sicherheit
|
||||||
|
NoNewPrivileges=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
ProtectHome=true
|
||||||
|
ReadWritePaths=/opt/myp-platform/backend/app/logs
|
||||||
|
ReadWritePaths=/opt/myp-platform/backend/app/database
|
||||||
|
ReadWritePaths=/opt/myp-platform/backend/app/uploads
|
||||||
|
ReadWritePaths=/opt/myp-platform/backend/app/certs
|
||||||
|
|
||||||
|
# Ressourcen-Limits
|
||||||
|
LimitNOFILE=65536
|
||||||
|
LimitNPROC=4096
|
||||||
|
MemoryMax=2G
|
||||||
|
CPUQuota=200%
|
||||||
|
|
||||||
|
# Timeouts
|
||||||
|
TimeoutStartSec=30
|
||||||
|
TimeoutStopSec=30
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
SyslogIdentifier=myp-platform
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
1
backend/app/nginx.conf
Normal file
1
backend/app/nginx.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user