Compare commits
4 Commits
361e7d7e6b
...
2be85606c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2be85606c5 | ||
|
|
db29f26d7a | ||
|
|
e8696ea656 | ||
|
|
0f86bfbc02 |
@@ -5,6 +5,5 @@ Roles for matrix services
|
|||||||
# To do
|
# To do
|
||||||
- Add argument spec validation
|
- Add argument spec validation
|
||||||
- Move ldap auth provider from password providers to collections
|
- Move ldap auth provider from password providers to collections
|
||||||
- Implement synchrotron balancing in nginx
|
|
||||||
- Make updates optional (use state: present instead of state: latest unless requested)
|
- Make updates optional (use state: present instead of state: latest unless requested)
|
||||||
- Only restart extras being changed, not all
|
- Only restart extras being changed, not all
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace: uumas
|
namespace: uumas
|
||||||
name: matrix
|
name: matrix
|
||||||
description: Matrix roles
|
description: Matrix roles
|
||||||
version: 0.0.1
|
version: 0.0.2
|
||||||
readme: README.md
|
readme: README.md
|
||||||
repository: https://git.uumas.fi/uumas/ansible-matrix
|
repository: https://git.uumas.fi/uumas/ansible-matrix
|
||||||
license_file: LICENSE
|
license_file: LICENSE
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
- name: Synapse
|
- name: Synapse
|
||||||
hosts: matrix_synapse
|
hosts: matrix_synapse
|
||||||
become: true
|
become: true
|
||||||
vars_files:
|
vars_files:
|
||||||
- vars/nginx.yml
|
- vars/nginx.yml
|
||||||
roles:
|
roles:
|
||||||
- synapse
|
- synapse
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ nginx_upstreams:
|
|||||||
additional_options:
|
additional_options:
|
||||||
- "client_max_body_size {{ matrix_max_upload_size_mb }}M"
|
- "client_max_body_size {{ matrix_max_upload_size_mb }}M"
|
||||||
|
|
||||||
synchrotron_balancer:
|
synapse_generic_sync:
|
||||||
servers: "{{ ['8183'] if synapse_workers.generic_sync is defined else '' }}"
|
servers: "{{ synapse_workers.generic_sync | default('') }}"
|
||||||
|
method: 'hash $mxid_localpart'
|
||||||
locations:
|
locations:
|
||||||
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/events$'
|
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/events$'
|
||||||
- name: "{{ '^/_matrix/client/(v2_alpha|r0|v3)/sync$' if 'generic_init_sync' not in synapse_workers | default('') else '' }}"
|
- name: "{{ '^/_matrix/client/(v2_alpha|r0|v3)/sync$' if 'generic_init_sync' not in synapse_workers | default('') else '' }}"
|
||||||
synchrotron_init:
|
synapse_generic_init_sync:
|
||||||
servers: "{{ ['8184'] if synapse_workers.generic_init_sync is defined else '' }}"
|
servers: "{{ synapse_workers.generic_init_sync | default('') }}"
|
||||||
|
method: 'hash $mxid_localpart'
|
||||||
locations:
|
locations:
|
||||||
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/initialSync$'
|
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/initialSync$'
|
||||||
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$'
|
- name: '~ ^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$'
|
||||||
@@ -166,7 +168,7 @@ nginx_upstreams:
|
|||||||
servers: "{{ synapse_workers.presence_persister | default('') }}"
|
servers: "{{ synapse_workers.presence_persister | default('') }}"
|
||||||
locations:
|
locations:
|
||||||
- name: '^/_matrix/client/(api/v1|r0|v3|unstable)/presence/'
|
- name: '^/_matrix/client/(api/v1|r0|v3|unstable)/presence/'
|
||||||
|
|
||||||
maubot:
|
maubot:
|
||||||
servers: "{{ ['29316'] if 'maubot' in matrix_extras | default('') else '' }}"
|
servers: "{{ ['29316'] if 'maubot' in matrix_extras | default('') else '' }}"
|
||||||
locations:
|
locations:
|
||||||
@@ -190,14 +192,25 @@ nginx_upstreams:
|
|||||||
|
|
||||||
nginx_maps:
|
nginx_maps:
|
||||||
sync:
|
sync:
|
||||||
var: "{{ 'arg_since' if synapse_workers.generic_sync is defined and synapse_workers.generic_init_sync is defined else '' }}"
|
var: "{{ 'arg_since' if synapse_workers.generic_sync is defined and synapse_workers.generic_init_sync is defined else '' }}"
|
||||||
rules:
|
rules:
|
||||||
default: synchrotron_balancer
|
default: synapse_generic_sync
|
||||||
"''": synchrotron_init
|
"''": synapse_generic_init_sync
|
||||||
locations:
|
locations:
|
||||||
- name: '~ ^/_matrix/client/(r0|v3)/sync$'
|
- name: '~ ^/_matrix/client/(r0|v3)/sync$'
|
||||||
additional_options:
|
additional_options:
|
||||||
- 'proxy_read_timeout 1h'
|
- 'proxy_read_timeout 1h'
|
||||||
|
mxid_localpart_urlparam:
|
||||||
|
var: arg_access_token
|
||||||
|
rules:
|
||||||
|
default: $arg_access_token
|
||||||
|
"'~syt_(?<username>.*?)_.*'": $username
|
||||||
|
mxid_localpart:
|
||||||
|
var: http_authorization
|
||||||
|
rules:
|
||||||
|
default: $http_authorization
|
||||||
|
"'~Bearer syt_(?<username>.*?)_.*'": $username
|
||||||
|
"''": $mxid_localpart_urlparam
|
||||||
|
|
||||||
nginx_servers:
|
nginx_servers:
|
||||||
- listen:
|
- listen:
|
||||||
@@ -225,14 +238,14 @@ nginx_servers:
|
|||||||
- synapse_main
|
- synapse_main
|
||||||
- matrix_media_repo
|
- matrix_media_repo
|
||||||
- synapse_media_repository
|
- synapse_media_repository
|
||||||
|
- synapse_generic_sync
|
||||||
|
- synapse_generic_init_sync
|
||||||
- synapse_generic_client
|
- synapse_generic_client
|
||||||
- synapse_generic_login
|
- synapse_generic_login
|
||||||
- synapse_generic_event_send
|
- synapse_generic_event_send
|
||||||
- synapse_generic_pagination
|
- synapse_generic_pagination
|
||||||
- synapse_user_dir
|
- synapse_user_dir
|
||||||
- synapse_frontend_proxy
|
- synapse_frontend_proxy
|
||||||
- synchrotron_balancer
|
|
||||||
- synchrotron_init
|
|
||||||
- synapse_device_persister
|
- synapse_device_persister
|
||||||
- synapse_typing_persister
|
- synapse_typing_persister
|
||||||
- synapse_account_persister
|
- synapse_account_persister
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ matrix_max_upload_size_mb: 100
|
|||||||
synapse_metrics: false
|
synapse_metrics: false
|
||||||
synapse_presence: true
|
synapse_presence: true
|
||||||
|
|
||||||
synchrotron_workers:
|
|
||||||
balancer: generic_sync
|
|
||||||
init: generic_init_sync
|
|
||||||
|
|
||||||
persister_workers:
|
persister_workers:
|
||||||
- event_persister
|
- event_persister
|
||||||
- typing_persister
|
- typing_persister
|
||||||
|
|||||||
@@ -21,3 +21,10 @@
|
|||||||
enabled: true
|
enabled: true
|
||||||
loop: "{{ synapse_worker_services }}"
|
loop: "{{ synapse_worker_services }}"
|
||||||
notify: Config matrix target
|
notify: Config matrix target
|
||||||
|
|
||||||
|
- name: Disable matrix-synchrotrons
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
name: matrix-synchrotron@{{ item }}.service
|
||||||
|
enabled: false
|
||||||
|
loop: "{{ synapse_synchrotrons }}"
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Ensure workdir exists for matrix-synchrotron-{{ item }}
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: /opt/matrix-synchrotron/{{ item }}
|
|
||||||
state: directory
|
|
||||||
mode: 0755
|
|
||||||
|
|
||||||
- name: Ensure config in place for matrix-synchrotron-{{ item }}
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: matrix-synchrotron-config.yaml.j2
|
|
||||||
dest: /opt/matrix-synchrotron/{{ item }}/config.yaml.ansibled
|
|
||||||
mode: 0644
|
|
||||||
notify: Config synapse service
|
|
||||||
register: config
|
|
||||||
|
|
||||||
- name: Copy config to final destination for matrix-synchrotron-{{ item }}
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: /opt/matrix-synchrotron/{{ item }}/config.yaml.ansibled
|
|
||||||
dest: /opt/matrix-synchrotron/{{ item }}/config.yaml
|
|
||||||
remote_src: true
|
|
||||||
mode: 0644
|
|
||||||
when: config.changed
|
|
||||||
@@ -1,53 +1,13 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Install git and golang
|
- name: Ensure matrix-synchrotron user not present
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- git
|
|
||||||
- golang
|
|
||||||
|
|
||||||
- name: Create matrix-synchrotron user
|
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: matrix-synchrotron
|
name: matrix-synchrotron
|
||||||
system: true
|
state: absent
|
||||||
home: /opt/matrix-synchrotron
|
remove: true
|
||||||
shell: /bin/false
|
|
||||||
|
|
||||||
- name: Install matrix-synchrotron
|
- name: Ensure matrix-synchrotron unit not present
|
||||||
become_user: matrix-synchrotron
|
ansible.builtin.file:
|
||||||
block:
|
path: /etc/systemd/system/matrix-synchrotron@.service
|
||||||
- name: Clone matrix-synchrotron git repo
|
state: absent
|
||||||
ansible.builtin.git:
|
notify: Disable matrix-synchrotrons
|
||||||
repo: https://github.com/Sorunome/matrix-synchrotron-balancer.git
|
|
||||||
dest: /opt/matrix-synchrotron/src
|
|
||||||
force: true
|
|
||||||
register: install
|
|
||||||
|
|
||||||
- name: Build matrix-synchrotron
|
|
||||||
ansible.builtin.command: go build
|
|
||||||
args:
|
|
||||||
chdir: /opt/matrix-synchrotron/src
|
|
||||||
when: install.changed
|
|
||||||
notify: Config synapse service
|
|
||||||
|
|
||||||
- name: Configure matrix-synchrotron(s)
|
|
||||||
ansible.builtin.include_tasks: matrix-synchrotron.yml
|
|
||||||
loop: "{{ synapse_synchrotrons }}"
|
|
||||||
loop_control:
|
|
||||||
extended: true
|
|
||||||
|
|
||||||
- name: Put systemd matrix-synchrotron unit in place
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: systemd/matrix-synchrotron@.service.j2
|
|
||||||
dest: /etc/systemd/system/matrix-synchrotron@.service
|
|
||||||
mode: "644"
|
|
||||||
register: systemd_unit
|
|
||||||
|
|
||||||
- name: Enable systemd unit matrix-synchrotron-{{ item }}
|
|
||||||
ansible.builtin.systemd:
|
|
||||||
daemon_reload: true
|
|
||||||
name: matrix-synchrotron@{{ item }}.service
|
|
||||||
enabled: true
|
|
||||||
state: restarted
|
|
||||||
when: systemd_unit.changed
|
|
||||||
loop: "{{ synapse_synchrotrons }}"
|
|
||||||
|
|||||||
@@ -27,26 +27,22 @@
|
|||||||
synapse_worker_services: []
|
synapse_worker_services: []
|
||||||
synapse_synchrotrons: []
|
synapse_synchrotrons: []
|
||||||
|
|
||||||
- name: Ensure worker pidfile dir in /run exists
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: /run/matrix-synapse/
|
|
||||||
state: directory
|
|
||||||
owner: matrix-synapse
|
|
||||||
group: nogroup
|
|
||||||
mode: 0755
|
|
||||||
|
|
||||||
- name: Ensure tmpfiles config for pidfile dir in place
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: tmpfiles-matrix-synapse.conf.j2
|
|
||||||
dest: /etc/tmpfiles.d/matrix-synapse.conf
|
|
||||||
mode: 0644
|
|
||||||
|
|
||||||
- name: Configure workers
|
- name: Configure workers
|
||||||
ansible.builtin.include_tasks: worker_type.yml
|
ansible.builtin.include_tasks: worker_type.yml
|
||||||
loop: "{{ synapse_workers | dict2items }}"
|
loop: "{{ synapse_workers | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: synapse_worker
|
loop_var: synapse_worker
|
||||||
|
|
||||||
- name: Configure synchrotron balancer
|
- name: Ensure worker pidfile dir in /run not present (legacy)
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /run/matrix-synapse/
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Ensure tmpfiles config for pidfile dir not present (legacy)
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/tmpfiles.d/matrix-synapse.conf
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Ensure synchrotron balancer removed (legacy)
|
||||||
ansible.builtin.include_tasks: matrix-synchrotrons.yml
|
ansible.builtin.include_tasks: matrix-synchrotrons.yml
|
||||||
when: synapse_synchrotrons | length != 0
|
when: synapse_synchrotrons | length != 0
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
homeserver_url: http://localhost:8008 # homeserver URL for the whoami request
|
|
||||||
listener: localhost:{{ 8183 + ansible_loop.index0 }} # host:port to listen to
|
|
||||||
|
|
||||||
synchrotrons:
|
|
||||||
{% for port in synapse_workers[synchrotron_workers[item]] %}
|
|
||||||
- address: 127.0.0.1:{{ port }}
|
|
||||||
pid_file: /run/matrix-synapse/{{ synchrotron_workers[item] }}-{{ loop.index0 }}.pid
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
balancer:
|
|
||||||
interval: 2
|
|
||||||
@@ -10,12 +10,10 @@ After=matrix-synapse.service
|
|||||||
[Service]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
NotifyAccess=main
|
NotifyAccess=main
|
||||||
PIDFile=/run/matrix-synapse/%i.pid
|
|
||||||
User=matrix-synapse
|
User=matrix-synapse
|
||||||
WorkingDirectory=/var/lib/matrix-synapse
|
WorkingDirectory=/var/lib/matrix-synapse
|
||||||
EnvironmentFile=-/etc/default/matrix-synapse
|
EnvironmentFile=-/etc/default/matrix-synapse
|
||||||
ExecStart=/opt/venvs/matrix-synapse/bin/python -m synapse.app.generic_worker --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --config-path=/etc/matrix-synapse/workers/%i.yaml
|
ExecStart=/opt/venvs/matrix-synapse/bin/python -m synapse.app.generic_worker --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --config-path=/etc/matrix-synapse/workers/%i.yaml
|
||||||
ExecStartPost=/bin/sh -c "echo $MAINPID > /run/matrix-synapse/%i.pid"
|
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=3
|
RestartSec=3
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
[Unit]
|
|
||||||
Description=Matrix Synchrotron %i
|
|
||||||
After=matrix-synapse.service
|
|
||||||
PartOf=matrix-synapse.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=matrix-synchrotron
|
|
||||||
WorkingDirectory=/opt/matrix-synchrotron/%i
|
|
||||||
ExecStart=/opt/matrix-synchrotron/src/matrix-synchrotron-balancer
|
|
||||||
Restart=always
|
|
||||||
RestartSec=3
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=matrix-synapse.service
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
d /run/matrix-synapse 0755 matrix-synapse nogroup - -
|
|
||||||
Reference in New Issue
Block a user