{% if pg.environment_variables %}

[supervisord]
environment={% for v in pg.environment_variables %}{{v.key}}="{{v.value}}",{% endfor %}
{% endif %}

[program:jingrow-bench-jingrow-web]
command=/home/jingrow/jingrow-bench/env/bin/gunicorn --bind 0.0.0.0:8000 --workers 2 --timeout 120 --graceful-timeout 30 --worker-tmp-dir /dev/shm jingrow.app:application --preload --max-requests 5000 --max-requests-jitter 1000

environment=FORWARDED_ALLOW_IPS="*"
priority=4
autostart=true
autorestart=true
stopwaitsecs=40
killasgroup=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/web.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/web.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench/sites

[program:jingrow-bench-jingrow-schedule]
command=bench schedule
priority=9
startsecs=0
autostart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/schedule.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/schedule.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench

{% if pg.use_rq_workerpool and pg.merge_all_rq_queues %}

[program:jingrow-bench-jingrow-worker]
command=bench worker-pool --queue short,default,long
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
process_name=%(program_name)s

{% elif pg.use_rq_workerpool %}

[program:jingrow-bench-jingrow-short-worker]
command=bench worker-pool --queue short,default
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=360
directory=/home/jingrow/jingrow-bench
killasgroup=true
process_name=%(program_name)s

[program:jingrow-bench-jingrow-long-worker]
command=bench worker-pool --queue long,default,short
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
process_name=%(program_name)s

{% elif pg.merge_all_rq_queues %}

[program:jingrow-bench-jingrow-worker]
command=bench worker --queue short,default,long
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

{% elif pg.merge_default_and_short_rq_queues %}

[program:jingrow-bench-jingrow-short-worker]
command=bench worker --queue short,default
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=360
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

[program:jingrow-bench-jingrow-long-worker]
command=bench worker --queue long,default,short
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

{% else %}

[program:jingrow-bench-jingrow-default-worker]
command=bench worker --queue default
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

[program:jingrow-bench-jingrow-short-worker]
command=bench worker --queue short
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=360
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

[program:jingrow-bench-jingrow-long-worker]
command=bench worker --queue long
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/worker.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/worker.error.log
user=jingrow
stopwaitsecs=1560
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

{% endif %}

{% if pg.custom_workers %}

{% for worker_name, config in pg.custom_workers.items() %}
[program:jingrow-bench-{{ worker_name }}-worker]
command=bench worker --queue {{ worker_name }}
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/{{ worker_name }}.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/{{ worker_name }}.error.log
user=jingrow
stopwaitsecs={{ config["timeout"]  }}
directory=/home/jingrow/jingrow-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d
{% endfor %}

{% endif %}

[program:jingrow-bench-redis-cache]
command=redis-server /home/jingrow/jingrow-bench/config/redis-cache.conf
priority=1
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/redis-cache.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/redis-cache.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench/sites

[program:jingrow-bench-redis-queue]
command=redis-server /home/jingrow/jingrow-bench/config/redis-queue.conf
priority=1
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/redis-queue.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/redis-queue.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench/sites

[program:jingrow-bench-node-socketio]
command=node /home/jingrow/jingrow-bench/apps/jingrow/socketio.js
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/node-socketio.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/node-socketio.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench

[group:jingrow-bench-web]
programs=jingrow-bench-jingrow-web,jingrow-bench-node-socketio

{% if pg.merge_all_rq_queues %}

[group:jingrow-bench-workers]
programs=jingrow-bench-jingrow-schedule,jingrow-bench-jingrow-worker

{% elif pg.merge_default_and_short_rq_queues or pg.use_rq_workerpool %}

[group:jingrow-bench-workers]
programs=jingrow-bench-jingrow-schedule,jingrow-bench-jingrow-short-worker,jingrow-bench-jingrow-long-worker

{% else %}

[group:jingrow-bench-workers]
programs=jingrow-bench-jingrow-schedule,jingrow-bench-jingrow-default-worker,jingrow-bench-jingrow-short-worker,jingrow-bench-jingrow-long-worker

{% endif %}

{% if pg.custom_workers_group %}

[group:jingrow-bench-custom_workers]
programs={{ pg.custom_workers_group }}

{% endif %}

[group:jingrow-bench-redis]
programs=jingrow-bench-redis-cache,jingrow-bench-redis-queue

{% if pg.is_code_server_enabled %}
[program:code-server]
command=code-server --bind-addr 0.0.0.0:8088 .
autostart=false
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/code-server.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/code-server.error.log
user=jingrow
directory=/home/jingrow/jingrow-bench/apps
{% endif %}

{% if pg.is_ssh_enabled %}
[program:sshd]
command=/usr/sbin/sshd -f /home/jingrow/jingrow-bench/config/ssh/sshd_config -D -e
autostart=true
autorestart=true
stdout_logfile=/home/jingrow/jingrow-bench/logs/ssh.log
stderr_logfile=/home/jingrow/jingrow-bench/logs/ssh.error.log
user=jingrow
directory=/home/jingrow
{% endif %}
