2023-12-03 21:56:21 +00:00
|
|
|
# {{ ansible_managed }}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% set service_systemd_service_options_keys = docker_systemd_service_systemd_service_options.keys() | list %}
|
|
|
|
{% set service_systemd_unit_options_keys = docker_systemd_service_systemd_unit_options.keys() | list %}
|
2023-12-03 21:56:21 +00:00
|
|
|
[Unit]
|
2023-12-04 22:10:02 +00:00
|
|
|
{% for key, value in docker_systemd_service_systemd_unit_options | dictsort %}
|
2023-12-03 21:56:21 +00:00
|
|
|
{{ key }}={{ value }}
|
|
|
|
{% endfor %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'After' in service_systemd_unit_options_keys %}
|
|
|
|
After=docker.service
|
|
|
|
{% endif %}
|
|
|
|
{% if not 'PartOf' in service_systemd_unit_options_keys %}
|
|
|
|
PartOf=docker.service
|
|
|
|
{% endif %}
|
|
|
|
{% if not 'Requires' in service_systemd_unit_options_keys %}
|
|
|
|
Requires=docker.service
|
|
|
|
{% endif %}
|
2023-12-03 21:56:21 +00:00
|
|
|
|
|
|
|
[Service]
|
2024-11-09 16:03:46 +00:00
|
|
|
{% for key, value in docker_systemd_service_systemd_service_options | dictsort %}
|
|
|
|
{{ key }}={{ value }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endfor %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'EnvironmentFile' in service_systemd_service_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
EnvironmentFile={{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'ExecStartPre' in service_systemd_service_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
ExecStartPre=-{{ docker_systemd_service_docker_path }} rm -f {{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'ExecStart' in service_systemd_service_options_keys %}
|
2023-12-10 16:32:52 +00:00
|
|
|
{% set docker_flags = docker_systemd_service_flags | create_docker_flags %}
|
2023-12-09 15:46:13 +00:00
|
|
|
ExecStart={{ docker_systemd_service_docker_path }} run --name {{ docker_systemd_service_container_name }} \
|
|
|
|
--rm \
|
|
|
|
--env-file {{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }} \
|
2023-12-10 16:32:52 +00:00
|
|
|
{{ docker_flags -}}{% if docker_flags +%}
|
|
|
|
{% endif %}{{ docker_systemd_service_image -}}{{ ' ' if docker_systemd_service_container_cmd else '' }}{% if docker_systemd_service_container_cmd is string %}{{ docker_systemd_service_container_cmd | trim }}{% else %}{{ docker_systemd_service_container_cmd | join(' ') | trim }}{% endif %}
|
2023-12-05 18:23:38 +00:00
|
|
|
{% endif +%}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'ExecStop' in service_systemd_service_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
ExecStop={{ docker_systemd_service_docker_path }} stop {{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if container_start_post is defined %}
|
|
|
|
ExecStartPost=-{{ container_start_post }}
|
|
|
|
{% endif %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'SyslogIdentifier' in service_systemd_service_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
SyslogIdentifier={{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'Restart' in service_systemd_service_options_keys %}
|
2023-12-03 21:56:21 +00:00
|
|
|
Restart=always
|
|
|
|
{% endif %}
|
2024-11-09 16:03:46 +00:00
|
|
|
{% if not 'RestartSec' in service_systemd_service_options_keys %}
|
2023-12-03 21:56:21 +00:00
|
|
|
RestartSec=10s
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
[Install]
|
2023-12-04 22:10:02 +00:00
|
|
|
WantedBy=docker.service
|