[supervisord]
environment =
    AA_USER = allianceserver,  ; The user under which the processes will run
    AA_PROJECT_NAME = {{ project_name }},  ; The name of the project
    AA_PROJECT_DIRECTORY = {{ project_directory }},  ; The directory of the project
    AA_VENV_DIRECTORY = {{ venv_directory }},  ; The directory of the virtual environment
    AA_COMMAND_CELERY = {{ celery }},  ; The command to run Celery
    AA_COMMAND_GUNICORN = {{ gunicorn }},  ; The command to run Gunicorn
    AA_COMMAND_MEMMON = {{ memmon }}  ; The command to run Memmon

[program:beat]
command = %(ENV_AA_COMMAND_CELERY)s
    -A %(ENV_AA_PROJECT_NAME)s beat
directory = %(ENV_AA_VENV_DIRECTORY)s
user = %(ENV_AA_USER)s
stdout_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
stderr_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
autostart = true
autorestart = true
startsecs = 10
priority = 998

[program:worker]
command = %(ENV_AA_COMMAND_CELERY)s
    -A %(ENV_AA_PROJECT_NAME)s worker
    --pool=threads
    --concurrency=5
    -n %(program_name)s_%(process_num)02d
directory = %(ENV_AA_VENV_DIRECTORY)s
user = %(ENV_AA_USER)s
numprocs = 1
process_name = %(program_name)s_%(process_num)02d
stdout_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
stderr_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
autostart = true
autorestart = true
startsecs = 10
stopwaitsecs = 600
killasgroup = true
priority = 998

{% if gunicorn %}
[program:gunicorn]
user = %(ENV_AA_USER)s
directory = %(ENV_AA_VENV_DIRECTORY)s
command = %(ENV_AA_COMMAND_GUNICORN)s %(ENV_AA_PROJECT_NAME)s.wsgi
    --workers=3
    --timeout 120
stdout_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
stderr_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/%(program_name)s.log
autostart = true
autorestart = true
stopsignal = INT
{% endif %}

[eventlistener:memmon]
command = %(ENV_AA_COMMAND_MEMMON)s
    -p worker_00=256MB
    -p gunicorn=256MB
directory = %(ENV_AA_VENV_DIRECTORY)s
events = TICK_60
stdout_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/memmon.log
stderr_logfile = %(ENV_AA_VENV_DIRECTORY)s/log/memmon.log

[group:{{ project_name }}]
programs = beat,worker{% if gunicorn %},gunicorn{% endif %}
priority = 999
