From dd96b93d899b7ba6c46cef8e93b86d5068b55ac8 Mon Sep 17 00:00:00 2001 From: Backslash Date: Fri, 27 Sep 2024 08:34:01 +1000 Subject: [PATCH] Update matrix-element-call.service.j2 --- .../systemd/matrix-element-call.service.j2 | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 b/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 index eded8dc6a..488b1f400 100644 --- a/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 +++ b/roles/custom/matrix-element-call/templates/systemd/matrix-element-call.service.j2 @@ -1,37 +1,31 @@ -[Unit] -Description=Matrix Element Call Service -After=docker.service -Requires=docker.service +{% if matrix_element_call_container_labels_traefik_enabled %} +traefik.enable=true -[Service] -Type=simple -Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-call 2>/dev/null || true' -ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-element-call 2>/dev/null || true' +{% if matrix_element_call_container_labels_traefik_docker_network %} +traefik.docker.network={{ matrix_element_call_container_labels_traefik_docker_network }} +{% endif %} -ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ - --rm \ - --name=matrix-element-call \ - --log-driver=none \ - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ - --cap-drop=ALL \ - --network={{ matrix_element_call_container_network }} \ - -p {{ matrix_element_call_port }}:8080 \ - --env-file={{ matrix_element_call_base_path }}/config/env \ - --label-file={{ matrix_element_call_base_path }}/config/element-call-labels \ - {{ matrix_element_call_image }} +# Define the Traefik router rule +traefik.http.routers.element-call-router.rule={{ matrix_element_call_container_labels_traefik_rule }} +traefik.http.routers.element-call-router.entrypoints={{ matrix_element_call_container_labels_traefik_entrypoints }} +traefik.http.routers.element-call-router.tls.certresolver={{ matrix_element_call_container_labels_traefik_tls_certResolver }} +traefik.http.services.element-call-service.loadbalancer.server.port=8080 -{% for network in matrix_element_call_container_additional_networks %} -ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-element-call -{% endfor %} +{% set middlewares = [] %} -ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-element-call +# Define any path prefix redirection or stripping middleware +{% if matrix_element_call_container_labels_traefik_path_prefix != '/' %} +traefik.http.middlewares.element-call-slashless-redirect.redirectregex.regex=({{ matrix_element_call_container_labels_traefik_path_prefix | quote }})$ +traefik.http.middlewares.element-call-slashless-redirect.redirectregex.replacement=${1}/ +{% set middlewares = middlewares + ['element-call-slashless-redirect'] %} -ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-element-call 2>/dev/null || true' -ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-element-call 2>/dev/null || true' -Restart=always -RestartSec=30 -SyslogIdentifier=matrix-element-call +traefik.http.middlewares.element-call-strip-prefix.stripprefix.prefixes={{ matrix_element_call_container_labels_traefik_path_prefix }} +{% set middlewares = middlewares + ['element-call-strip-prefix'] %} +{% endif %} -[Install] -WantedBy=multi-user.target +# Add middlewares to the router +{% if middlewares | length > 0 %} +traefik.http.routers.element-call-router.middlewares={{ middlewares | join(',') }} +{% endif %} + +{% endif %}