[Unit]
Description=Freva web server
After=network.target

[Service]
Type=simple
ProtectSystem=full
PermissionsStartOnly=true
NoNewPrivileges=true
ProtectHome=true
KillSignal=SIGTERM
User={{uid}}
Group={{gid}}
ExecStart=/bin/sh -c "PATH={{ conda_path }}/bin:$PATH {{conda_path}}/libexec/freva-web/init_django.sh 1> {{ data_dir }}/log/freva-web.out.log 2> {{ data_dir }}/log/freva-web.err.log "
ExecStartPost=/bin/sh -c "PATH={{ conda_path }}/bin:$PATH nginx -c {{data_dir}}/freva_web.conf &"
Environment="CONDA_PREFIX={{ conda_path }}"
Environment="EVALUATION_SYSTEM_CONFIG_FILE={{core_root_dir|regex_replace('^~', ansible_env.HOME)}}/freva/evaluation_system.conf"
Environment="DJANGO_SUPERUSER_PASSWORD={{ root_passwd }}"
Environment="ALLOWED_HOSTS={{web_allowed_hosts | join(',')}}"
Environment="FREVA_WEB_CONFIG_FILE={{web_config_file}}"
Environment="SCHEDULER_HOST={{web_scheduler_host | join(',')}}"
Environment="DJANGO_SUPERUSER_EMAIL=freva@dkrz.de"
Environment="REDIS_HOST={{web_redis_host_name}}"
{% for env in redis_settings %}
Environment="{{env}}"
{% endfor %}
Environment="CSRF_TRUSTED_ORIGINS={{web_csrf_trusted_origins | join(',')}}"
Environment="FREVA_BIN={{web_freva_bin}}"
Environment="COLUMNS=140"
Environment="FREVA_REST_URL=http://{{web_freva_rest_host}}"
WorkingDirectory={{conda_path}}/libexec/freva-web
UMask=007
Restart=on-failure
RestartSec=5
StartLimitBurst=5

[Install]
WantedBy=multi-user.target
