#!/usr/bin/env bash

# {{ '{{' }} ansible_managed }}

{{ '{%' }} set {{ role_name }}_venv_bin = {{ role_name }}_home + "/venvs/" + {{ role_name }}_service_name + "/bin" %}
{{ '{%' }} if COMMON_ENABLE_NEWRELIC_APP %}
{{ '{%' }} set executable = {{ role_name }}_venv_bin + '/newrelic-admin run-program ' + {{ role_name }}_venv_bin + '/gunicorn' %}
{{ '{%' }} else %}
{{ '{%' }} set executable = {{ role_name }}_venv_bin + '/gunicorn' %}
{{ '{%' }} endif %}

{{ '{%' }} if COMMON_ENABLE_NEWRELIC_APP %}
export NEW_RELIC_APP_NAME="{{ '{{' }} {{ role_name|upper }}_NEWRELIC_APPNAME }}"
export NEW_RELIC_LICENSE_KEY="{{ '{{' }} NEWRELIC_LICENSE_KEY }}"
{{ '{%' }} endif -%}

source {{ '{{' }} {{ role_name }}_home }}/{{ role_name }}_env
{{ '{{' }} executable }} -c {{ '{{' }} {{ role_name }}_home }}/{{ role_name }}_gunicorn.py {{ '{{' }} {{ role_name|upper }}_GUNICORN_EXTRA }} {{ role_name }}.wsgi:application
