ansible-collection-famedly-.../roles/synapse/tasks/configure_workers.yml
Johanna Dorothea Reichmann 1985813915
feat(synapse): add support for deploying workers
Can deploy synapse workers and allow costum amounts of workers for each
type. For documentation on how to use, see `roles/synapse/README.md`.

In a docker deployment, each worker runs in their own docker container
with respective listener configurations. Labels can be declared in
`tasks/configure_workers.yml` for routing of requests.

In systemd deployments, each worker runs in it's own systemd service,
which are marked as being part of the main service, so restarting the
main service will restart all the workers as well.
2020-11-23 08:55:07 +01:00

207 lines
7.8 KiB
YAML

---
# Client API config (multiple instances)
- name: Collect client API worker config
set_fact:
worker_client_info: "{{ worker_client_info|default([]) + [ worker|from_yaml ] }}"
vars:
name: "worker_client_{{ item }}"
app: "synapse.app.generic_worker"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
port: "{{ (matrix_synapse_worker_listener_base_port|int + item|int)|int }}"
worker: |
name: "{{ name }}"
app: "{{ app }}"
port: "{{ port }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports:
- "{{ matrix_synapse_worker_listener_bind_base_ip }}:{{ port }}:{{ port }}"
listeners:
- type: http
port: {{ port }}
resources:
- names: [ client ]
loop: "{{ range(1, matrix_synapse_workers_client + 1) | list }}"
# Federation API (inbound) config (multiple instances, federation listener)
- name: Collect federation API worker config (inbound)
set_fact:
worker_fed_in_info: "{{ worker_fed_in_info|default([]) + [ worker|from_yaml ] }}"
vars:
name: "worker_fed_in_{{ item }}"
app: "synapse.app.generic_worker"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
port: "{{ matrix_synapse_worker_listener_base_port|int + 100 + item|int }}"
worker: |
name: "{{ name }}"
app: "{{ app }}"
port: "{{ port }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports:
- "{{ matrix_synapse_worker_listener_bind_base_ip }}:{{ port }}:{{ port }}"
listeners:
- type: http
port: {{ port|int }}
resources:
- names: [ federation ]
loop: "{{ range(1, matrix_synapse_workers_federation_in + 1) | list }}"
# Federation sender config (multiple instances)
- name: Collect federation sender worker config (outbound)
set_fact:
worker_fed_out_info: "{{ worker_fed_out_info|default([]) + [ worker|from_yaml ] }}"
vars:
name: "worker_fed_out_{{ item }}"
app: "synapse.app.federation_sender"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
worker: |
name: "{{ name }}"
app: "{{ app }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports: []
listeners: []
loop: "{{ range(1, matrix_synapse_workers_federation_out + 1) | list }}"
# Media workers config (multiple instances)
- name: Collect media worker config
set_fact:
worker_media_info: "{{ worker_media_info|default([]) + [ worker|from_yaml ] }}"
vars:
name: "worker_media_{{ item }}"
app: "synapse.app.media_repository"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
port: "{{ matrix_synapse_worker_listener_base_port|int + 200 + item|int }}"
worker: |
name: "{{ name }}"
app: "{{ app }}"
port: "{{ port }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports:
- "{{ matrix_synapse_worker_listener_bind_base_ip }}:{{ port }}:{{ port }}"
listeners:
- type: http
port: {{ port|int }}
resources:
- names: [ media ]
loop: "{{ range(1, matrix_synapse_workers_media + 1) | list }}"
# Pusher worker config (single instance)
- name: Collect pusher worker config
set_fact:
worker_pusher_info: "{{ [ worker|from_yaml ] }}"
vars:
name: "worker_pusher"
app: "synapse.app.pusher"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
worker: |
name: "{{ name }}"
app: "{{ app }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports: []
listeners: []
when: matrix_synapse_worker_push
# Appservice worker config (single instance)
- name: Collect appservice worker config
set_fact:
worker_appservice_info: "{{ [ worker|from_yaml ] }}"
vars:
name: "worker_appservice"
app: "synapse.app.appservice"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
worker: |
name: "{{ name }}"
app: "{{ app }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports: []
listeners: []
when: matrix_synapse_worker_appservice
# Userdirectory worker config (single instance)
- name: Collect user directory worker config
set_fact:
worker_user_dir_info: "{{ [ worker|from_yaml ] }}"
vars:
name: "worker_user_dir"
app: "synapse.app.user_dir"
config_file: "{{ matrix_synapse_base_path }}/{{ name }}.yaml"
port: "{{ matrix_synapse_worker_listener_base_port|int + 300 }}"
worker: |
name: "{{ name }}"
app: "{{ app }}"
port: "{{ port }}"
config_file: "{{ config_file }}"
service_name: "matrix-{{ name }}.service"
container_name: "{{ matrix_synapse_container_name }}_{{ name }}"
container_command: "-m {{ app }} -c {{ matrix_synapse_base_path }}/homeserver.yaml -c {{ config_file }}"
extra_volumes:
- "{{ config_file }}:{{ config_file }}:z"
labels: {}
ports:
- "{{ matrix_synapse_worker_listener_bind_base_ip }}:{{ port }}:{{ port }}"
listeners:
- type: http
port: {{ port }}
resources:
- names: [ client ]
when: matrix_synapse_worker_user_search
- name: Collect worker configuration
set_fact:
matrix_synapse_workers: "{{ worker_client_info|default([]) + worker_fed_in_info|default([]) + worker_fed_out_info|default([]) + worker_media_info|default([]) + worker_pusher_info|default([]) + worker_appservice_info|default([]) + worker_user_dir_info|default([]) }}"
- name: Write worker configuration files
copy:
content: |
worker_app: {{ item.app }}
worker_name: {{ item.name }}
worker_replication_host: {{ matrix_synapse_worker_replication_host }}
worker_replication_http_port: {{ matrix_synapse_worker_replication_port }}
{% if item.listeners|length > 0 or matrix_synapse_worker_metrics_enabled %}
worker_listeners:
{{ (item.listeners + ([ matrix_synapse_worker_metrics_listener ] if matrix_synapse_worker_metrics_enabled else [])) | to_nice_yaml }}
{% endif %}
dest: "{{ item.config_file }}"
owner: synapse
group: synapse
mode: 0640
loop: "{{ matrix_synapse_workers }}"