Files
squid-manager/wsgi.py
T
Your Name 931a64dbc8 feat: add one-click deploy script + project optimization
- deploy.sh: one-click deployment (squid + venv + pip + gunicorn + systemd)
- gunicorn_config.py: unified gunicorn config with env var overrides
- .env.example: env var template for SECRET_KEY, port, workers, security
- wsgi.py: create all runtime dirs (uploads, ssl_certs); optional dotenv loading
- requirements.txt: add python-dotenv + cryptography
- .gitignore: cover runtime dirs, .env, pyc files
2026-09-09 13:23:36 +08:00

33 lines
915 B
Python

"""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)")