#!/bin/bash

GUNICORN_PORT='8080'
GUNICORN_WORKERS=${GUNICORN_WORKERS-'2'}
GUNICORN_THREADS=${GUNICORN_THREADS-'5'}
GUNICORN_TIMEOUT='90'
GUNICORN_KEEPALIVE='90'


cd /var/env

. bin/activate

cd /var/app


DDTRACE_BINARY=$(whereis ddtrace-run | cut -d ' ' -f 2)
if [ -x ${DDTRACE_BINARY} ]; then
  ${DDTRACE_BINARY} gunicorn -k uvicorn.workers.UvicornWorker "application:app" --bind "0.0.0.0:${GUNICORN_PORT}" --workers ${GUNICORN_WORKERS} --threads ${GUNICORN_THREADS} --timeout ${GUNICORN_TIMEOUT} --keep-alive ${GUNICORN_KEEPALIVE}
else
  gunicorn -k uvicorn.workers.UvicornWorker "application:app" --bind "0.0.0.0:${GUNICORN_PORT}" --workers ${GUNICORN_WORKERS} --threads ${GUNICORN_THREADS} --timeout ${GUNICORN_TIMEOUT} --keep-alive ${GUNICORN_KEEPALIVE}
fi
