{%- if unit_file.unit is defined -%}
[Unit]
{%- if unit_file.unit.description is not none %}
Description={{ unit_file.unit.description }}
{%- endif %}
{%- if unit_file.unit.documentation is not none %}
Documentation={{ unit_file.unit.documentation | join(' ') }}
{%- endif %}
{%- if unit_file.unit.requires_mounts_for is not none %}
RequiresMountsFor={{ unit_file.unit.requires_mounts_for | join(' ') }}
{%- endif %}
{%- for requires in unit_file.unit.requires %}
Requires={{ requires }}
{%- endfor %}
{%- for wants in unit_file.unit.wants %}
Wants={{ wants }}
{%- endfor %}
{%- for binds_to in unit_file.unit.binds_to %}
BindsTo={{ binds_to }}
{%- endfor %}
{%- for before in unit_file.unit.before %}
Before={{ before }}
{%- endfor %}
{%- for after in unit_file.unit.after %}
After={{ after }}
{%- endfor %}
{%- for part_of in unit_file.unit.part_of %}
PartOf={{ part_of }}
{%- endfor %}

{% endif -%}

{%- if unit_file.service is defined -%}
[Service]
{%- for name, value in unit_file.service.environment.items() %}
Environment={{ name }}={{ value }}
{%- endfor %}
{%- if unit_file.service.restart is not none %}
Restart={{ unit_file.service.restart }}
{%- endif %}
{%- if unit_file.service.timeout_start_sec is not none %}
TimeoutStartSec={{ unit_file.service.timeout_start_sec }}
{%- endif %}
{%- if unit_file.service.timeout_sec is not none %}
TimeoutSec={{ unit_file.service.timeout_sec }}
{%- endif %}
{%- if unit_file.service.timeout_stop_sec is not none %}
TimeoutStopSec={{ unit_file.service.timeout_stop_sec }}
{%- endif %}
{%- if unit_file.service.restart_sec is not none %}
RestartSec={{ unit_file.service.restart_sec }}
{%- endif %}
{%- for exec_start_pre in unit_file.service.exec_start_pre %}
ExecStartPre={{ exec_start_pre }}
{%- endfor %}
{%- if unit_file.service.exec_start is not none %}
ExecStart={{ unit_file.service.exec_start }}
{%- endif %}
{%- for exec_start_post in unit_file.service.exec_start_post %}
ExecStartPost={{ exec_start_post }}
{%- endfor %}
{%- for exec_stop_pre in unit_file.service.exec_stop_pre %}
ExecStopPre={{ exec_stop_pre }}
{%- endfor %}
{%- if unit_file.service.exec_stop is not none %}
ExecStop={{ unit_file.service.exec_stop }}
{%- endif %}
{%- for exec_stop_post in unit_file.service.exec_stop_post %}
ExecStopPost={{ exec_stop_post }}
{%- endfor %}
{%- if unit_file.service.type is not none %}
Type={{ unit_file.service.type }}
{%- endif %}
{%- if unit_file.service.notify_access is not none %}
NotifyAccess={{ unit_file.service.notify_access }}
{%- endif %}
{%- if unit_file.service.pid_file is not none %}
PIDFile={{ unit_file.service.pid_file }}
{%- endif %}

{% endif -%}

{% if unit_file.timer is defined -%}
[Timer]
{%- if unit_file.timer.on_calendar is not none %}
OnCalendar={{ unit_file.timer.on_calendar }}
{%- endif %}
{%- if unit_file.timer.accuracy_sec is not none %}
AccuracySec={{ unit_file.timer.accuracy_sec }}
{%- endif %}
{%- if unit_file.timer.randomized_delay_sec is not none %}
RandomizedDelaySec={{ unit_file.timer.randomized_delay_sec }}
{%- endif %}
{%- if unit_file.timer.unit is not none %}
Unit={{ unit_file.timer.unit }}
{%- endif %}

{% endif -%}

{% if unit_file.socket is defined -%}
[Socket]
{%- for listen_stream in unit_file.socket.listen_stream %}
ListenStream={{ listen_stream }}
{%- endfor %}
{%- if unit_file.socket.service is not none %}
Service={{ unit_file.socket.service }}
{%- endif %}

{% endif -%}

{%- if unit_file.install is defined -%}
[Install]
{%- if unit_file.install.alias is not none %}
Alias={{ unit_file.install.alias | join(' ') }}
{%- endif %}
{%- for wanted_by in unit_file.install.wanted_by %}
WantedBy={{ wanted_by }}
{%- endfor %}
{%- for required_by in unit_file.install.required_by %}
RequiredBy={{ required_by }}
{%- endfor %}

{% endif -%}
