"""WSGI entry point for gunicorn. Run with: gunicorn --workers 2 --bind 0.0.0.0:5200 wsgi:app Or via systemd unit. """ import os # Ensure runtime dirs exist before app imports (it references SQLite path etc.) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) for _d in ("instance", "backups", "uploads", "ssl_certs"): os.makedirs(os.path.join(BASE_DIR, _d), exist_ok=True) # Optional: load .env file if python-dotenv is available try: from dotenv import load_dotenv _env_path = os.path.join(BASE_DIR, ".env") if os.path.isfile(_env_path): load_dotenv(_env_path) except ImportError: pass from app import app, db, seed_admin with app.app_context(): try: db.create_all() seed_admin() except Exception as e: # multi-worker race - the first worker wins; subsequent ones log print(f"[wsgi] DB init: {e} (likely race with another worker)")