#35 use gunicorn for running the backend in production
This commit is contained in:
parent
7d5d821bae
commit
66f818e54f
@ -38,13 +38,16 @@ services:
|
||||
image: registry.gitlab.com/champs-libres/geonature-citizen/back
|
||||
volumes:
|
||||
- ./vendor/GeoNature-citizen/backend/gncitizen/:/home/appuser/citizen/backend/gncitizen/
|
||||
- ./vendor/GeoNature-citizen/backend/var/log/:/home/appuser/citizen/backend/var/log/
|
||||
- ./patches/settings.ini:/home/appuser/citizen/config/settings.ini
|
||||
- ./patches/settings.ini:/home/appuser/citizen/backend/config/settings.ini
|
||||
- ./patches/back/default_config.toml:/home/appuser/citizen/config/default_config.toml
|
||||
- ./patches/back/start_gunicorn.sh:/home/appuser/citizen/backend/start_gunicorn.sh
|
||||
- ./patches/back/wsgi.py:/home/appuser/citizen/backend/wsgi.py
|
||||
- ./patches/back/server.py:/home/appuser/citizen/backend/server.py
|
||||
ports:
|
||||
- "5002:5002"
|
||||
command: python wsgi.py
|
||||
command: bash start_gunicorn.sh
|
||||
taxhub:
|
||||
build:
|
||||
dockerfile: ./Dockerfile-taxhub
|
||||
@ -57,7 +60,9 @@ services:
|
||||
- ./patches/taxhub/server.py:/home/appuser/taxhub/server.py
|
||||
- ./patches/taxhub/install_db.sh:/home/appuser/taxhub/install_db.sh
|
||||
- ./patches/taxhub/settings.ini:/home/appuser/taxhub/settings.ini
|
||||
command: python server.py
|
||||
- ./patches/taxhub/gunicorn_start.sh:/home/appuser/taxhub/gunicorn_start.sh
|
||||
- ./vendor/TaxHub/var/log/:/home/appuser/taxhub/var/log/
|
||||
command: bash gunicorn_start.sh
|
||||
|
||||
media:
|
||||
build:
|
||||
|
30
patches/back/start_gunicorn.sh
Executable file
30
patches/back/start_gunicorn.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
echo "------------------------------------------------"
|
||||
echo "GeoNature-citizen backend server is starting ..."
|
||||
echo "------------------------------------------------"
|
||||
|
||||
|
||||
FLASKDIR=$(readlink -e "${0%/*}")
|
||||
APP_DIR="$(dirname "$FLASKDIR")"
|
||||
|
||||
. $APP_DIR/config/settings.ini
|
||||
|
||||
echo "info: Starting $app_name"
|
||||
echo "info: FLASKDIR: $FLASKDIR"
|
||||
echo "info: APP_DIR: $APP_DIR"
|
||||
|
||||
# Start your gunicorn
|
||||
LOG_DIR="$APP_DIR/var/log"
|
||||
echo "LOG_DIR: $LOG_DIR"
|
||||
if [[ ! -e $LOG_DIR ]]; then
|
||||
mkdir -p $LOG_DIR
|
||||
elif [[ ! -d $LOG_DIR ]]; then
|
||||
echo "LOG_DIR already exists but is not a directory" 1>&2
|
||||
fi
|
||||
export PYTHONPATH=`pwd`/${venv_dir}
|
||||
#echo $PYTHONPATH
|
||||
echo "info: Starting gunicorn"
|
||||
echo "--"
|
||||
exec gunicorn -w ${gun_num_workers:-2} --error-log $APP_DIR/var/log/gunicorn_gncitizen_errors.log --pid="${app_name:-"gncitizen"}.pid" -b ${gun_host:-"0.0.0.0"}:${gun_port:-5002} --timeout=${gun_timeout:-30} --reload -n "geonature-citizen" wsgi:app
|
@ -1,5 +1,5 @@
|
||||
# Langue du serveur
|
||||
# valeur possible : fr_FR.UTF-8, en_US.utf8
|
||||
# valeur possible : fr_FR.UTF-8, en_US.utf8
|
||||
# locale -a pour voir la liste des locales disponible
|
||||
my_local=fr_FR.UTF-8
|
||||
|
||||
@ -25,7 +25,7 @@ admin_password=MotDePasseAChanger
|
||||
################################
|
||||
|
||||
|
||||
# Localisation du server PostgreSQL.
|
||||
# Localisation du server PostgreSQL.
|
||||
# Les scripts d'installation automatique ne fonctionnent que si votre BDD est sur le même serveur (localhost)
|
||||
pg_host=db
|
||||
# Port sur lequel PostgreSQL ecoute
|
||||
@ -43,6 +43,6 @@ user_pg_pass=postgres
|
||||
|
||||
app_name=gncitizen
|
||||
gun_num_workers=2
|
||||
gun_host=localhost
|
||||
gun_host=0.0.0.0
|
||||
gun_port=5002
|
||||
gun_timeout=30
|
||||
|
20
patches/taxhub/gunicorn_start.sh
Executable file
20
patches/taxhub/gunicorn_start.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
FLASKDIR=$(readlink -e "${0%/*}")
|
||||
APP_DIR="$(dirname "$FLASKDIR")"
|
||||
|
||||
echo "Starting $app_name"
|
||||
echo "$FLASKDIR"
|
||||
echo "$APP_DIR"
|
||||
|
||||
. "$APP_DIR"/settings.ini
|
||||
|
||||
# # activate the virtualenv
|
||||
# cd $FLASKDIR/$venv_dir
|
||||
# source bin/activate
|
||||
|
||||
# export PYTHONPATH=$FLASKDIR:$PYTHONPATH
|
||||
|
||||
|
||||
# Start your unicorn
|
||||
exec gunicorn server:app --access-logfile $APP_DIR/var/log/taxhub-access.log --pid="${app_name}.pid" --error-log $APP_DIR/var/log/taxhub-errors.log -w "${gun_num_workers}" -b "${gun_host}:${gun_port}" -n "${app_name}"
|
Loading…
Reference in New Issue
Block a user