From 0c40a03efce77c7afb726c094e18dac5404176c8 Mon Sep 17 00:00:00 2001 From: Aine Date: Sun, 8 Mar 2026 07:24:33 +0000 Subject: [PATCH] allow synapse to use redis unix socket instead of tcp --- group_vars/matrix_servers | 4 ++++ roles/custom/matrix-synapse/defaults/main.yml | 9 +++++++-- .../matrix-synapse/templates/synapse/homeserver.yaml.j2 | 5 +++++ .../synapse/systemd/matrix-synapse-worker.service.j2 | 3 +++ .../templates/synapse/systemd/matrix-synapse.service.j2 | 3 +++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index e3dda9acd..4294aca39 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -4844,6 +4844,10 @@ matrix_synapse_redis_enabled: "{{ valkey_enabled }}" matrix_synapse_redis_host: "{{ valkey_identifier if valkey_enabled else '' }}" matrix_synapse_redis_password: "{{ valkey_connection_password if valkey_enabled else '' }}" +matrix_synapse_redis_path_enabled: false # temporarily, then switch to true by default once properly tested +matrix_synapse_redis_path: "{{ '/tmp/redis.sock' if valkey_enabled else '' }}" # default value for Synapse +matrix_synapse_redis_path_host: "{{ valkey_run_path+'/valkey.sock' if valkey_enabled else '' }}" # path on the host + matrix_synapse_container_extra_arguments_auto: "{{ matrix_homeserver_container_extra_arguments_auto }}" matrix_synapse_app_service_config_files_auto: "{{ matrix_homeserver_app_service_config_files_auto }}" diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index bd46a2e2b..336d1824a 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -1241,11 +1241,16 @@ matrix_synapse_instance_map: | # Redis information matrix_synapse_redis_enabled: false -matrix_synapse_redis_host: "" -matrix_synapse_redis_port: 6379 matrix_synapse_redis_password: "" matrix_synapse_redis_dbid: 0 matrix_synapse_redis_use_tls: false +# Connection option 1: TCP +matrix_synapse_redis_host: "" +matrix_synapse_redis_port: 6379 +# Connection option 2: Unix socket (takes precedence over TCP if `matrix_synapse_redis_path` is set) +matrix_synapse_redis_path_enabled: false +matrix_synapse_redis_path: "" # the path to the redis socket inside the container, e.g. "/var/run/redis.sock" +matrix_synapse_redis_path_host: "" # the path to the redis socket on the host, e.g. "/matrix/valkey/run/valkey.sock" # Controls whether Synapse starts a replication listener necessary for workers. # diff --git a/roles/custom/matrix-synapse/templates/synapse/homeserver.yaml.j2 b/roles/custom/matrix-synapse/templates/synapse/homeserver.yaml.j2 index 61c306ef3..84ed4e5fa 100644 --- a/roles/custom/matrix-synapse/templates/synapse/homeserver.yaml.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/homeserver.yaml.j2 @@ -2932,6 +2932,11 @@ redis: host: {{ matrix_synapse_redis_host | to_json }} port: {{ matrix_synapse_redis_port | to_json }} + # The full path to a local Unix socket file. If this is used, host and port are ignored. + {% if matrix_synapse_redis_path_enabled %} + path: {{ matrix_synapse_redis_path | to_json }} + {% endif %} + # Optional database ID to connect to. Defaults to 0. dbid: {{ matrix_synapse_redis_dbid | to_json }} diff --git a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 index 54558dc39..086fe287b 100644 --- a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse-worker.service.j2 @@ -67,6 +67,9 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ {% for volume in matrix_synapse_container_additional_volumes %} --mount type={{ volume.type | default('bind' if '/' in volume.src else 'volume') }},src={{ volume.src }},dst={{ volume.dst }}{{ (',' + volume.options) if volume.options else '' }} \ {% endfor %} + {% if matrix_synapse_redis_path_enabled %} + --mount type=bind,src={{ matrix_synapse_redis_path_host }},dst={{ matrix_synapse_redis_path }} \ + {% endif %} --label-file={{ matrix_synapse_base_path }}/{{ matrix_synapse_worker_labels_file_name }} \ {% for arg in matrix_synapse_container_arguments %} {{ arg }} \ diff --git a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 index a3bcc0bc0..ecf09a64b 100644 --- a/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/systemd/matrix-synapse.service.j2 @@ -51,6 +51,9 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ {% endif %} --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data,ro \ --mount type=bind,src={{ matrix_synapse_storage_path }},dst=/matrix-media-store-parent,bind-propagation=slave \ + {% if matrix_synapse_redis_path_enabled %} + --mount type=bind,src={{ matrix_synapse_redis_path_host }},dst={{ matrix_synapse_redis_path }} \ + {% endif %} --label-file={{ matrix_synapse_base_path }}/labels \ {% for volume in matrix_synapse_container_additional_volumes %} --mount type={{ volume.type | default('bind' if '/' in volume.src else 'volume') }},src={{ volume.src }},dst={{ volume.dst }}{{ (',' + volume.options) if volume.options else '' }} \