diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 98c49fbbe..160f3de38 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -1289,8 +1289,23 @@ matrix_synapse_workers_media_repository_workers_container_arguments: [] # matrix_synapse_enable_media_repo controls if the main Synapse process should serve media repository endpoints or if it should be left to media_repository workers (see `matrix_synapse_workers_media_repository_workers_count`). # This is enabled if workers are disabled, or if they are enabled, but there are no media repository workers. +# It's also enabled if there are no `quarantined_media_changes` stream writer workers. +# The main process then remains the writer for that stream, and Synapse requires the writer to be media-capable in order to serve the quarantine admin APIs. +# This does not make the main process run the media repository's main background jobs, as those are assigned via `matrix_synapse_media_instance_running_background_jobs`. +# Since `homeserver.yaml` is shared with workers, worker configuration files disable it again for the other workers in this case (see `worker.yaml.j2`). # Adjusting this value manually is generally not necessary. -matrix_synapse_enable_media_repo: "{{ not matrix_synapse_ext_media_repo_enabled and (not matrix_synapse_workers_enabled or (matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'media_repository') | list | length == 0)) }}" +matrix_synapse_enable_media_repo: |- + {{ + not matrix_synapse_ext_media_repo_enabled + and + ( + not matrix_synapse_workers_enabled + or + (matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'media_repository') | list | length == 0) + or + (matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'quarantined_media_changes') | list | length == 0) + ) + }} # matrix_synapse_enable_local_media_storage controls whether the local on-disk media storage provider is enabled in Synapse. # When disabled, media is stored only in configured `media_storage_providers` and temporary files are used for processing (no local caching). diff --git a/roles/custom/matrix-synapse/templates/synapse/worker.yaml.j2 b/roles/custom/matrix-synapse/templates/synapse/worker.yaml.j2 index 60c1fd057..bf07a8aa9 100644 --- a/roles/custom/matrix-synapse/templates/synapse/worker.yaml.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/worker.yaml.j2 @@ -20,6 +20,13 @@ worker_log_config: /data/{{ matrix_server_fqn_matrix }}.log.config ) %} {% if is_media_capable_quarantined_media_changes_stream_writer %} enable_media_repo: true +{% elif matrix_synapse_worker_details.type != 'media_repository' and matrix_synapse_enable_media_repo | bool and matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'media_repository') | list | length > 0 %} +{# + `enable_media_repo` is only enabled in `homeserver.yaml` despite there being media repository workers + so that the main process can serve the quarantine admin APIs (see `matrix_synapse_enable_media_repo`). + Other workers (besides media repository workers) should not load the media repository (and run its background tasks), so we disable it for them. +#} +enable_media_repo: false {% endif %} {% set http_resources = [] %}