mirror of https://github.com/interlegis/sapl.git
10 changed files with 205 additions and 110 deletions
@ -0,0 +1,74 @@ |
|||
# /var/interlegis/sapl/gunicorn.conf.py |
|||
|
|||
import os |
|||
import pathlib |
|||
import multiprocessing |
|||
|
|||
# ---- SAPL app configuration ---- |
|||
NAME = "SAPL" |
|||
DJANGODIR = "/var/interlegis/sapl/" |
|||
SOCKFILE = "/var/interlegis/sapl/run/gunicorn.sock" |
|||
# USER = os.getenv("RUN_AS_USER", os.getenv("USER", "nginx")) |
|||
# GROUP = os.getenv("RUN_AS_GROUP", USER) |
|||
NUM_WORKERS = 11 # keep your explicit value |
|||
TIMEOUT = 300 |
|||
MAX_REQUESTS = 100 |
|||
DJANGO_SETTINGS = "sapl.settings" |
|||
WSGI_APP = "sapl.wsgi:application" |
|||
|
|||
# ---- gunicorn settings ---- |
|||
# Equivalent of: --name |
|||
proc_name = NAME |
|||
|
|||
# Equivalent of: --bind=unix:... |
|||
# For quick testing via browser, you can switch to: bind = "0.0.0.0:8000" |
|||
bind = f"unix:{SOCKFILE}" |
|||
|
|||
# Ensure imports work like in your script’s working dir |
|||
chdir = DJANGODIR |
|||
|
|||
# Allow starting with just: gunicorn -c gunicorn.conf.py |
|||
wsgi_app = WSGI_APP |
|||
|
|||
# Logs |
|||
loglevel = "debug" |
|||
errorlog = "-" # send to stderr (so you see it in docker logs or terminal) |
|||
accesslog = "-" # send to stdout |
|||
# accesslog = "/var/log/sapl/access.log" |
|||
# errorlog = "/var/log/sapl/error.log" |
|||
|
|||
# Worker/process lifecycle |
|||
workers = NUM_WORKERS |
|||
timeout = TIMEOUT |
|||
graceful_timeout = 30 |
|||
max_requests = MAX_REQUESTS |
|||
max_requests_jitter = 0 |
|||
|
|||
# Drop privileges (only applies if started as root) |
|||
# user = USER |
|||
# group = GROUP |
|||
|
|||
# Environment (same as exporting before running) |
|||
raw_env = [ |
|||
f"DJANGO_SETTINGS_MODULE={DJANGO_SETTINGS}", |
|||
# If you’re using ReportLab and seeing segfaults with PDFs, keep this: |
|||
# "RL_NOACCEL=1", |
|||
] |
|||
|
|||
# If you previously enabled preload and saw segfaults with native libs, keep it off: |
|||
preload_app = False |
|||
|
|||
|
|||
# Create the run/ directory for the UNIX socket (your script did this) |
|||
def on_starting(server): |
|||
pathlib.Path(SOCKFILE).parent.mkdir(parents=True, exist_ok=True) |
|||
|
|||
|
|||
# Close DB connections after fork (safer when using preload or certain DB drivers) |
|||
def post_fork(server, worker): |
|||
try: |
|||
from django import db |
|||
db.connections.close_all() |
|||
except Exception: |
|||
# Django not initialized yet or not available |
|||
pass |
@ -1,50 +0,0 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
## |
|||
## |
|||
## PARA USO EXCLUSIVO DO CONTAINER DOCKER DO SAPL!!! |
|||
## EVITE USAR PARA CHAMADA DIRETAS |
|||
## |
|||
## |
|||
|
|||
# As seen in http://tutos.readthedocs.org/en/latest/source/ndg.html |
|||
|
|||
SAPL_DIR="/var/interlegis/sapl" |
|||
|
|||
# Seta um novo diretório foi passado como raiz para o SAPL |
|||
# caso esse tenha sido passado como parâmetro |
|||
if [ "$1" ] |
|||
then |
|||
SAPL_DIR="$1" |
|||
fi |
|||
|
|||
NAME="SAPL" # Name of the application (*) |
|||
DJANGODIR=/var/interlegis/sapl/ # Django project directory (*) |
|||
SOCKFILE=/var/interlegis/sapl/run/gunicorn.sock # we will communicate using this unix socket (*) |
|||
USER=`whoami` # the user to run as (*) |
|||
GROUP=`whoami` # the group to run as (*) |
|||
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn (*) |
|||
# NUM_WORKERS = 2 * CPUS + 1 |
|||
TIMEOUT=300 |
|||
MAX_REQUESTS=100 # number of requests before restarting worker |
|||
DJANGO_SETTINGS_MODULE=sapl.settings # which settings file should Django use (*) |
|||
DJANGO_WSGI_MODULE=sapl.wsgi # WSGI module name (*) |
|||
|
|||
echo "Starting $NAME as `whoami` on base dir $SAPL_DIR" |
|||
|
|||
# Create the run directory if it doesn't exist |
|||
RUNDIR=$(dirname $SOCKFILE) |
|||
test -d $RUNDIR || mkdir -p $RUNDIR |
|||
|
|||
# Start your Django Unicorn |
|||
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon) |
|||
exec gunicorn ${DJANGO_WSGI_MODULE}:application \ |
|||
--name $NAME \ |
|||
--log-level debug \ |
|||
--timeout $TIMEOUT \ |
|||
--workers $NUM_WORKERS \ |
|||
--max-requests $MAX_REQUESTS \ |
|||
--user $USER \ |
|||
--access-logfile /var/log/sapl/access.log \ |
|||
--error-logfile /var/log/sapl/error.log \ |
|||
--bind=unix:$SOCKFILE |
Loading…
Reference in new issue