#!/bin/sh
set -e

MODULE_NAME=${MODULE_NAME:-"app.main"}
VARIABLE_NAME=${VARIABLE_NAME:-"app"}
export APP_MODULE="${APP_MODULE:-"$MODULE_NAME:$VARIABLE_NAME"}"
export GUNICORN_CONF="${GUNICORN_CONF:-"/usr/local/share/uvicorn-gunicorn/gunicorn_conf.py"}"
export WORKER_CLASS="${WORKER_CLASS:-"uvicorn.workers.UvicornWorker"}"

if [ -f "${PRE_START_PATH}" ] ; then
    echo "Running script ${PRE_START_PATH}"
    # shellcheck disable=SC1090
    . "${PRE_START_PATH}"
fi

# Start Gunicorn
exec gunicorn \
    -k "${WORKER_CLASS}" \
    -c "${GUNICORN_CONF}" \
    "${APP_MODULE}"
