alterações gerais
This commit is contained in:
@ -1,29 +1,51 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
set -o nounset
|
||||
|
||||
# Configurações ajustáveis via variáveis de ambiente
|
||||
PORT=${GUNICORN_PORT:-8005}
|
||||
WORKERS=${GUNICORN_WORKERS:-$(( $(nproc) * 2 + 1 ))}
|
||||
TIMEOUT=${GUNICORN_TIMEOUT:-120}
|
||||
MAX_REQUESTS=${GUNICORN_MAX_REQUESTS:-1000}
|
||||
|
||||
# Aplica migrações do banco de dados (com tratamento de erro)
|
||||
python /app/manage.py migrate --noinput || {
|
||||
echo "⚠️ Falha nas migrações do banco de dados!";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Coleta arquivos estáticos
|
||||
python /app/manage.py collectstatic --noinput
|
||||
|
||||
# Verifica e comprime arquivos (se compressor ativado)
|
||||
compress_enabled() {
|
||||
python << END
|
||||
python << END
|
||||
import sys
|
||||
|
||||
from environ import Env
|
||||
|
||||
env = Env(COMPRESS_ENABLED=(bool, True))
|
||||
if env('COMPRESS_ENABLED'):
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0 if env('COMPRESS_ENABLED') else 1)
|
||||
END
|
||||
}
|
||||
|
||||
if compress_enabled; then
|
||||
# NOTE this command will fail if django-compressor is disabled
|
||||
python /app/manage.py compress
|
||||
python /app/manage.py compress --verbosity=0 || {
|
||||
echo "⚠️ Falha ao comprimir arquivos (django-compressor pode estar desativado)";
|
||||
}
|
||||
fi
|
||||
exec /usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app
|
||||
|
||||
# Inicia o Gunicorn com configurações otimizadas
|
||||
exec /usr/local/bin/gunicorn config.wsgi:application \
|
||||
--bind 0.0.0.0:${PORT} \
|
||||
--workers ${WORKERS} \
|
||||
--timeout ${TIMEOUT} \
|
||||
--max-requests ${MAX_REQUESTS} \
|
||||
--worker-class sync \
|
||||
--name diarios_oficiais_alems \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
--chdir=/app
|
||||
|
||||
|
||||
Reference in New Issue
Block a user