#!/bin/bash

# Modeled closely after flask portion of amazon/aws-eb-python:3.4.2-onbuild-3.5.1 entrypoint script

UWSGI_NUM_PROCESSES='1'
UWSGI_NUM_THREADS='15'
UWSGI_UID='uwsgi'
UWSGI_GID='uwsgi'
UWSGI_LOG_FILE='/var/log/uwsgi/uwsgi.log'
# increase header buffer size if one is seeing 502s & 'invalid request block size' errors in uwsgi log
UWSGI_BUFFER_SIZE='12288'
UWSGI_TIMEOUT='90'
UWSGI_HEADERS='Connection:Keep-Alive'

cd /var/app

# Flask support
if cat poetry.lock | grep -q -i Flask && [ -z "${WSGI_MODULE}" ]; then
  UWSGI_MODULE='--module application:app'
fi

# defaulting to application.py if not explicitly set
[ -z "${WSGI_PATH}" ] && WSGI_PATH=application.py



python3 ~/.poetry/bin/poetry run uwsgi --enable-threads --lazy-apps --http :8080 --cache2 name=uwsgi_cache,items=10 --chdir /var/app --wsgi-file ${WSGI_PATH} ${UWSGI_MODULE} --master --processes ${UWSGI_NUM_PROCESSES} --threads ${UWSGI_NUM_THREADS} --uid ${UWSGI_UID} --gid ${UWSGI_GID} --http-keepalive --buffer-size ${UWSGI_BUFFER_SIZE}
