docker_systemd_service/templates/unit.j2

44 lines
2.0 KiB
Plaintext
Raw Normal View History

2023-12-03 21:56:21 +00:00
# {{ ansible_managed }}
2023-12-04 22:10:02 +00:00
{% set service_systemd_options_keys = docker_systemd_service_systemd_options | selectattr("key") | map(attribute="key") | 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 %}
[Service]
2023-12-04 22:10:02 +00:00
{% for item in docker_systemd_service_systemd_options %}
2023-12-03 21:56:21 +00:00
{{ item['key'] }}={{ item['value'] }}
{% endfor %}
{% if not 'EnvironmentFile' in service_systemd_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 %}
{% if not 'ExecStartPre' in service_systemd_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 %}
{% if not 'ExecStart' in service_systemd_options_keys %}
{% set docker_flags = docker_systemd_service_flags | create_docker_flags %}
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 }} \
{{ 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 %}
{% endif +%}
2023-12-03 21:56:21 +00:00
{% if not 'ExecStop' in service_systemd_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 %}
{% if not 'SyslogIdentifier' in service_systemd_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 %}
{% if not 'Restart' in service_systemd_options_keys %}
Restart=always
{% endif %}
{% if not 'RestartSec' in service_systemd_options_keys %}
RestartSec=10s
{% endif %}
[Install]
2023-12-04 22:10:02 +00:00
WantedBy=docker.service