· needs documentation; no checks yet for port clashes or typos in worker name · according to https://github.com/matrix-org/synapse/wiki/Workers-setup-with-nginx#results about 90% of requests go to the synchrotron endpoint · thus, the synchrotron worker is especially suited to be load-balanced · most of the other workers are documented to support only a single instance · https://github.com/matrix-org/synapse/blob/master/docs/workers.mddevelopment
parent
f8ada98c19
commit
353bc7c362
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/workers/setup_install.yml"
|
||||
when: "matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool"
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/workers/setup_uninstall.yml"
|
||||
when: "not matrix_synapse_workers_enabled|bool"
|
@ -0,0 +1,41 @@
|
||||
---
|
||||
|
||||
- name: Ensure synapse worker base service file installed
|
||||
template:
|
||||
src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse-worker@.service.j2"
|
||||
dest: "{{ matrix_systemd_path }}/matrix-synapse-worker@.service"
|
||||
mode: 0644
|
||||
register: matrix_synapse_worker_systemd_service_result
|
||||
|
||||
- name: Ensure previous worker service symlinks are cleaned (FIXME)
|
||||
file:
|
||||
path: "{{ item.root + '/' + item.path }}"
|
||||
state: absent
|
||||
when:
|
||||
- item.state == 'link'
|
||||
- item.path is match('matrix-synapse-worker@*.service')
|
||||
with_filetree:
|
||||
- "{{ matrix_systemd_path }}/matrix-synapse.service.wants"
|
||||
|
||||
- name: Ensure systemd reloaded the worker service unit
|
||||
service:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Ensure individual worker service symlinks exist
|
||||
service:
|
||||
name: "matrix-synapse-worker@{{ item.worker }}:{{ item.port }}.service"
|
||||
enabled: true
|
||||
with_items: "{{ matrix_synapse_workers_enabled_list }}"
|
||||
|
||||
- name: Ensure creation of specific worker configs
|
||||
template:
|
||||
src: "{{ role_path }}/templates/synapse/worker.yaml.j2"
|
||||
dest: "{{ matrix_synapse_config_dir_path }}/worker.{{ item.worker }}:{{ item.port }}.yaml"
|
||||
with_list: "{{ matrix_synapse_workers_enabled_list }}"
|
||||
|
||||
- name: Add workers to synapse.wants list
|
||||
set_fact:
|
||||
matrix_synapse_systemd_wanted_services_list: >
|
||||
{{ matrix_synapse_systemd_wanted_services_list +
|
||||
['matrix-synapse-worker@' + item.worker + ':' + item.port|string + '.service'] }}
|
||||
with_items: "{{ matrix_synapse_workers_enabled_list }}"
|
@ -0,0 +1,34 @@
|
||||
---
|
||||
|
||||
- name: Ensure individual worker services are stopped
|
||||
service:
|
||||
name: "matrix-synapse-worker@{{ item.worker }}:{{ item.port }}.service"
|
||||
state: stopped
|
||||
with_items: "{{ matrix_synapse_workers_enabled_list }}"
|
||||
|
||||
# As we cannot know the ports of workers removed from the enabled_list..
|
||||
# => .. just kill them all (FIXME?)
|
||||
- name: Ensure previous worker service symlinks are cleaned
|
||||
file:
|
||||
path: "{{ item.root + '/' + item.path }}"
|
||||
state: absent
|
||||
when:
|
||||
- item.state == 'link'
|
||||
- item.path is match('matrix-synapse-worker@*.service')
|
||||
with_filetree:
|
||||
- "{{ matrix_systemd_path }}/matrix-synapse.service.wants"
|
||||
|
||||
- name: Ensure synapse worker base service file gets removed
|
||||
file:
|
||||
path: "{{ matrix_systemd_path }}/matrix-synapse-worker@.service"
|
||||
state: absent
|
||||
register: matrix_synapse_worker_systemd_service_result
|
||||
|
||||
- name: Remove workers from synapse.wants list
|
||||
set_fact:
|
||||
matrix_synapse_systemd_wanted_services_list: "{{ matrix_synapse_systemd_wanted_services_list | reject('search', item) | list }}"
|
||||
with_items: "{{ matrix_synapse_workers_avail_list }}"
|
||||
|
||||
- name: Ensure systemd noticed removal of worker service units
|
||||
service:
|
||||
daemon_reload: yes
|
@ -0,0 +1,29 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
# c.f. https://github.com/matrix-org/synapse/pull/4662
|
||||
[Unit]
|
||||
Description=Synapse Matrix Worker
|
||||
After=matrix-synapse.service
|
||||
BindsTo=matrix-synapse.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
||||
# Intentional delay, so that the homeserver (we likely depend on) can manage to start.
|
||||
ExecStartPre=/bin/sleep 5
|
||||
|
||||
# systemd ftw 🤦♂️
|
||||
# https://github.com/systemd/systemd/issues/14895#issuecomment-594123923
|
||||
ExecStart=/bin/sh -c "WORKER=%i; WORKER=$${WORKER%%:*}; \
|
||||
exec /usr/bin/docker exec \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
matrix-synapse \
|
||||
python -m synapse.app.$${WORKER} -c /data/homeserver.yaml -c /data/worker.%i.yaml"
|
||||
|
||||
ExecStop=/usr/bin/docker exec matrix-synapse pkill -f %i
|
||||
KillMode=process
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
SyslogIdentifier=matrix-synapse-%i
|
||||
|
||||
[Install]
|
||||
WantedBy=matrix-synapse.service
|
@ -0,0 +1,29 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
worker_app: synapse.app.{{ item.worker }}
|
||||
|
||||
worker_replication_host: 127.0.0.1
|
||||
worker_replication_port: {{ matrix_synapse_replication_tcp_port }}
|
||||
worker_replication_http_port: {{ matrix_synapse_replication_http_port }}
|
||||
|
||||
{% if item.worker not in [ 'appservice', 'federation_sender', 'pusher' ] %}
|
||||
worker_listeners:
|
||||
- type: http
|
||||
port: {{ item.port }}
|
||||
resources:
|
||||
- names:
|
||||
{% if item.worker in [ 'synchrotron', 'client_reader', 'event_creator', 'frontend_proxy', 'user_dir' ] %}
|
||||
- client
|
||||
{% elif item.worker in [ 'federation_reader' ] %}
|
||||
- federation
|
||||
{% elif item.worker in [ 'media_repository' ] %}
|
||||
- media
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if item.worker == 'frontend_proxy' %}
|
||||
worker_main_http_uri: http://127.0.0.1:8008
|
||||
{% endif %}
|
||||
|
||||
worker_daemonize: false
|
||||
worker_pid_file: /matrix-run/{{ item.worker }}.port{{ item.port }}.pid
|
||||
worker_log_config: /data/{{ matrix_server_fqn_matrix }}.log.config
|
Loading…
Reference in new issue