[Unit]
Description={{ service.name }}
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=60

[Service]
Type=simple
WorkingDirectory={{ unit_vars.working_dir | default('/opt') }}
Environment="CUDA_VISIBLE_DEVICES={{ settings.cuda_devices | default('0') }}"
{% for key, value in extra_env.items() %}
Environment="{{ key }}={{ value }}"
{% endfor %}

ExecStart={{ settings.uvicorn_bin | default('uvicorn') }} \
    {{ unit_vars.app_module | default('main:app') }} \
    --port {{ service.port }} \
    --host 0.0.0.0{% if unit_vars.workers is defined %} \
    --workers {{ unit_vars.workers }}{% endif %}{% if unit_vars.extra_args is defined %} \
    {{ unit_vars.extra_args }}{% endif %}

Restart=on-failure
RestartSec=30

[Install]
WantedBy=default.target
