synapse workers: polishing, cleansing and installation of jq dependency

This commit is contained in:
Marcel Partap 2020-10-23 20:49:53 +02:00
parent 501efee07e
commit a4125d5446
4 changed files with 44 additions and 14 deletions

View file

@ -1,8 +1,7 @@
--- ---
# a negative when condition will not actually prevent ansible from executing loops in imported tasks!
- import_tasks: "{{ role_path }}/tasks/workers/setup_install.yml" - include_tasks: "{{ role_path }}/tasks/workers/setup_install.yml"
when: "matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool" when: "matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool"
- import_tasks: "{{ role_path }}/tasks/workers/setup_uninstall.yml" - include_tasks: "{{ role_path }}/tasks/workers/setup_uninstall.yml"
when: "not matrix_synapse_workers_enabled|bool" when: "not matrix_synapse_workers_enabled|bool"

View file

@ -7,12 +7,11 @@
mode: 0644 mode: 0644
register: matrix_synapse_worker_systemd_service_result register: matrix_synapse_worker_systemd_service_result
- name: Ensure previous worker service symlinks are cleaned (FIXME) - name: Ensure previous worker service symlinks are cleaned
file: file:
path: "{{ item.root + '/' + item.path }}" path: "{{ item.root + '/' + item.path }}"
state: absent state: absent
when: when:
- matrix_synapse_workers_enabled|bool
- item.state == 'link' - item.state == 'link'
- item.path is match('matrix-synapse-worker@.*\\.service') - item.path is match('matrix-synapse-worker@.*\\.service')
with_filetree: with_filetree:
@ -28,6 +27,13 @@
enabled: true enabled: true
with_items: "{{ matrix_synapse_workers_enabled_list }}" with_items: "{{ matrix_synapse_workers_enabled_list }}"
- name: Ensure previous worker configs are cleaned
file:
path: "{{ item }}"
state: absent
with_fileglob:
- "{{ matrix_synapse_config_dir_path }}/worker.*.yaml"
- name: Ensure creation of specific worker configs - name: Ensure creation of specific worker configs
template: template:
src: "{{ role_path }}/templates/synapse/worker.yaml.j2" src: "{{ role_path }}/templates/synapse/worker.yaml.j2"
@ -46,3 +52,24 @@
src: "{{ role_path }}/files/usr-local-bin/matrix-synapse-worker-write-pid" src: "{{ role_path }}/files/usr-local-bin/matrix-synapse-worker-write-pid"
dest: "{{ matrix_local_bin_path }}/matrix-synapse-worker-write-pid" dest: "{{ matrix_local_bin_path }}/matrix-synapse-worker-write-pid"
mode: 0750 mode: 0750
- name: Ensure jq is installed (Archlinux)
pacman:
name:
- jq
state: present
when: (ansible_distribution == 'Archlinux')
- name: Ensure jq is installed (CentOS)
yum:
name:
- jq
state: present
when: (ansible_distribution == 'CentOS')
- name: Ensure jq is installed (Debian)
apt:
name:
- jq
state: present
when: (ansible_os_family == 'Debian')

View file

@ -9,14 +9,11 @@
state: stopped state: stopped
with_dict: "{{ ansible_facts.services|default({})|dict2items|selectattr('key', 'match', 'matrix-synapse-worker@.+\\.service')|list|items2dict }}" with_dict: "{{ ansible_facts.services|default({})|dict2items|selectattr('key', 'match', 'matrix-synapse-worker@.+\\.service')|list|items2dict }}"
# As we cannot know the ports of workers removed from the enabled_list.. - name: Ensure worker service symlinks are cleaned
# => .. just kill them all (FIXME?)
- name: Ensure previous worker service symlinks are cleaned
file: file:
path: "{{ item.root + '/' + item.path }}" path: "{{ item.root + '/' + item.path }}"
state: absent state: absent
when: when:
- not matrix_synapse_workers_enabled|bool
- item.state == 'link' - item.state == 'link'
- item.path is match('matrix-synapse-worker@.*\\.service') - item.path is match('matrix-synapse-worker@.*\\.service')
with_filetree: with_filetree:
@ -28,6 +25,13 @@
state: absent state: absent
register: matrix_synapse_worker_systemd_service_result register: matrix_synapse_worker_systemd_service_result
- name: Ensure worker configs are cleaned
file:
path: "{{ item.root + '/' + item.path }}"
state: absent
with_fileglob:
- "{{ matrix_synapse_config_dir_path }}/worker.*.yaml"
- name: Remove workers from synapse.wants list - name: Remove workers from synapse.wants list
set_fact: set_fact:
matrix_synapse_systemd_wanted_services_list: "{{ matrix_synapse_systemd_wanted_services_list | reject('search', item) | list }}" matrix_synapse_systemd_wanted_services_list: "{{ matrix_synapse_systemd_wanted_services_list | reject('search', item) | list }}"

View file

@ -11,21 +11,21 @@ BindsTo=matrix-synapse.service
[Service] [Service]
Type=simple Type=simple
# Intentional delay, so that the homeserver (we likely depend on) can manage to start. # Intentional delay, so that the homeserver can manage to start.
ExecStartPre=/bin/sleep 5 ExecStartPre={{ matrix_host_command_sleep }} 5
# no sane way of instancing more than one variable (systemd "cant-fix" 🤦) # no sane way of instancing more than one variable (systemd "cant-fix" 🤦)
# c.f. https://github.com/systemd/systemd/issues/14895#issuecomment-594123923 # c.f. https://github.com/systemd/systemd/issues/14895#issuecomment-594123923
# So use good ol' shell parameter expansion to get the worker type.. # So use good ol' shell parameter expansion to get the worker type..
ExecStart=/bin/sh -c "WORKER=%i; WORKER=$${WORKER%%:*}; \ ExecStart=/bin/sh -c "WORKER=%i; WORKER=$${WORKER%%:*}; \
exec /usr/bin/docker exec \ exec {{ matrix_host_command_docker }} exec \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
matrix-synapse \ matrix-synapse \
python -m synapse.app.$${WORKER} -c /data/homeserver.yaml -c /data/worker.%i.yaml" python -m synapse.app.$${WORKER} -c /data/homeserver.yaml -c /data/worker.%i.yaml"
# wait for worker startup & write out PID of actual worker process so systemd can handle it # wait for worker startup & write out PID of actual worker process so systemd can handle it
ExecStartPost=/bin/sleep 5 ExecStartPost={{ matrix_host_command_sleep }} 5
ExecStartPost=/usr/local/bin/matrix-synapse-worker-write-pid %i /run/matrix-synapse-worker.%i.pid ExecStartPost={{ matrix_local_bin_path }}/matrix-synapse-worker-write-pid %i /run/matrix-synapse-worker.%i.pid
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill $MAINPID ExecStop=/bin/kill $MAINPID