docker_systemd_service/templates/unit.j2
Bertrand Lanson 8c9bdfbea5
All checks were successful
development / Check commit compliance (push) Successful in 5s
test / Retrieve Credentials (pull_request) Successful in 1s
pull-requests-open / Check commit compliance (pull_request) Successful in 5s
test / end_to_end_role (default, debian11) (pull_request) Successful in 39s
test / end_to_end_role (default, debian12) (pull_request) Successful in 38s
test / end_to_end_role (default, ubuntu2004) (pull_request) Successful in 40s
test / end_to_end_role (default, ubuntu2204) (pull_request) Successful in 39s
test / end_to_end_role (default, ubuntu2404) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, debian11) (pull_request) Successful in 38s
test / end_to_end_role (with_custom_flags, debian12) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2004) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2204) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2404) (pull_request) Successful in 40s
feat: enable customization of unit options in systemd file
This also adjusts the unit.j2 template accordingly, as well as update documentation for the role.

It also updates tests to cover more scenarios
2024-11-09 17:03:46 +01:00

54 lines
2.4 KiB
Django/Jinja

# {{ 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 %}
[Unit]
{% for key, value in docker_systemd_service_systemd_unit_options | dictsort %}
{{ 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 %}
[Service]
{% for key, value in docker_systemd_service_systemd_service_options | dictsort %}
{{ key }}={{ value }}
{% endfor %}
{% if not 'EnvironmentFile' in service_systemd_service_options_keys %}
EnvironmentFile={{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}
{% endif %}
{% if not 'ExecStartPre' in service_systemd_service_options_keys %}
ExecStartPre=-{{ docker_systemd_service_docker_path }} rm -f {{ docker_systemd_service_container_name }}
{% 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 %}
ExecStop={{ docker_systemd_service_docker_path }} stop {{ docker_systemd_service_container_name }}
{% endif %}
{% if container_start_post is defined %}
ExecStartPost=-{{ container_start_post }}
{% endif %}
{% if not 'SyslogIdentifier' in service_systemd_service_options_keys %}
SyslogIdentifier={{ docker_systemd_service_container_name }}
{% endif %}
{% if not 'Restart' in service_systemd_service_options_keys %}
Restart=always
{% endif %}
{% if not 'RestartSec' in service_systemd_service_options_keys %}
RestartSec=10s
{% endif %}
[Install]
WantedBy=docker.service