docker_systemd_service/templates/unit.j2

54 lines
2.4 KiB
Plaintext
Raw Normal View History

2023-12-03 21:56:21 +00:00
# {{ ansible_managed }}
{% 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 %}
{% 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]
{% for key, value in docker_systemd_service_systemd_service_options | dictsort %}
{{ key }}={{ value }}
2023-12-03 21:56:21 +00:00
{% endfor %}
{% 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 %}
{% 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 %}
{% if not 'ExecStart' in service_systemd_service_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 +%}
{% 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 %}
{% 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 %}
{% if not 'Restart' in service_systemd_service_options_keys %}
2023-12-03 21:56:21 +00:00
Restart=always
{% endif %}
{% 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