[Unit]
Description = A Gunicorn Webserver for {{ hostname }}.
After = network.target

[Service]
User = www-data
Group = www-data
WorkingDirectory = /srv/www/{{ hostname }}
EnvironmentFile = /srv/www/{{ hostname }}/.env
TimeoutSec = 1200

ExecStartPre = +/srv/www/{{ hostname }}/.venv/bin/manage.py migrate --noinput
ExecStartPre = +/srv/www/{{ hostname }}/.venv/bin/manage.py collectstatic --noinput
ExecStartPre = /srv/www/{{ hostname }}/.venv/bin/manage.py add_institutions --from-file /srv/www/{{ hostname }}/initial/institutions.json
ExecStartPre = /srv/www/{{ hostname }}/.venv/bin/manage.py add_users --from-file /srv/www/{{ hostname }}/initial/users.json
ExecStartPre = /srv/www/{{ hostname }}/.venv/bin/manage.py add_datasets --from-file /srv/www/{{ hostname }}/initial/datasets.json
ExecStartPre = /srv/www/{{ hostname }}/.venv/bin/manage.py add_riskmodels --from-file /srv/www/{{ hostname }}/initial/riskmodels.json
ExecStart = /srv/www/{{ hostname }}/.venv/bin/python -m gunicorn -c /srv/www/{{ hostname }}/gunicorn.conf.py

ExecReload = kill -s HUP $MAINPID
ExecStop = kill -s TERM $MAINPID
PrivateTmp = true

[Install]
WantedBy = multi-user.target
