forked from ungleich-public/cdist-contrib
[__matrix_synapse_worker] initial implementation
This commit is contained in:
parent
2bcc815555
commit
37762dd1ca
9 changed files with 203 additions and 0 deletions
|
@ -0,0 +1,25 @@
|
|||
[Unit]
|
||||
Description=Synapse %i
|
||||
AssertPathExists=/etc/matrix-synapse/workers/%i.yaml
|
||||
|
||||
# This service should be restarted when the synapse target is restarted.
|
||||
PartOf=matrix-synapse.target
|
||||
|
||||
# if this is started at the same time as the main, let the main process start
|
||||
# first, to initialise the database schema.
|
||||
After=matrix-synapse.service
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
NotifyAccess=main
|
||||
User=matrix-synapse
|
||||
WorkingDirectory=/var/lib/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
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
SyslogIdentifier=matrix-synapse-%i
|
||||
|
||||
[Install]
|
||||
WantedBy=matrix-synapse.target
|
25
type/__matrix_synapse_worker/files/worker.yaml.sh
Executable file
25
type/__matrix_synapse_worker/files/worker.yaml.sh
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
|
||||
cat << EOF
|
||||
worker_app: "${WORKER_APP:?}"
|
||||
worker_name: "${WORKER_NAME:?}"
|
||||
|
||||
# The replication listener on the main synapse process.
|
||||
worker_replication_host: "${WORKER_REPLICATION_HOST:?}"
|
||||
worker_replication_http_port: "${WORKER_REPLICATION_PORT:?}"
|
||||
|
||||
worker_listeners:
|
||||
- type: http
|
||||
port: "${WORKER_PORT:?}"
|
||||
resources:
|
||||
- names:
|
||||
EOF
|
||||
|
||||
for resource in ${WORKER_RESOURCES:?}; do
|
||||
echo " - \"$resource\""
|
||||
done
|
||||
|
||||
cat << EOF
|
||||
|
||||
worker_log_config: "${WORKER_LOG_CONFIG:?}"
|
||||
EOF
|
77
type/__matrix_synapse_worker/man.rst
Normal file
77
type/__matrix_synapse_worker/man.rst
Normal file
|
@ -0,0 +1,77 @@
|
|||
cdist-type__matrix_synapse(7)
|
||||
======================
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__matrix_synapse_worker - Configure a synapse worker
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This type configures and start a matrix worker. This type does not install
|
||||
synapse: `cdist-type__matrix_synapse(7) <cdist-type__matrix_synapse.html>`_
|
||||
type must be run first.
|
||||
|
||||
It is also recommended to take a look at:
|
||||
|
||||
- `upstream's high-level overview on workers (matrix.org blog post) <https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability>`_
|
||||
- `upstream's documentation on workers <https://github.com/matrix-org/synapse/blob/develop/docs/workers.md>`_
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
app
|
||||
Worker application to be used. A detailed list is available on `upstream's
|
||||
documentation
|
||||
<https://github.com/matrix-org/synapse/blob/master/docs/workers.md#available-worker-applications>`_.
|
||||
|
||||
port
|
||||
Port on which this worker will listen.
|
||||
|
||||
resource
|
||||
Resources to be served by this worker. Can be specified multiple times.
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
replication-host
|
||||
Replication endpoint host of your main synapse process. Defaults to
|
||||
localhost.
|
||||
|
||||
replication-port
|
||||
Replication endpoint port of your main synapse process. Defaults to 9093.
|
||||
|
||||
log-config
|
||||
Path to log configuration. Defaults to synapse's main process log
|
||||
configuration.
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
__matrix_synapse --server-name ungleich.ch \
|
||||
--base-url https://matrix.ungleich.ch \
|
||||
--database-engine sqlite3 \
|
||||
--database-name /var/lib/matrix-syanpse/homeserver.db \
|
||||
--worker-mode
|
||||
require="__matrix_synapse" __matrix_synapse_worker generic \
|
||||
--app 'synapse.app.generic_worker' \
|
||||
--port 8083 \
|
||||
--resource 'federation' \
|
||||
--resource 'client'
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- `cdist-type__matrix_synapse(7) <cdist-type__matrix_synapse.html>`_
|
||||
|
||||
|
||||
AUTHORS
|
||||
-------
|
||||
Timothée Floure <timothee.floure@ungleich.ch>
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2019-2021 Timothée Floure. You can redistribute it
|
||||
and/or modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
67
type/__matrix_synapse_worker/manifest
Executable file
67
type/__matrix_synapse_worker/manifest
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/bin/sh
|
||||
|
||||
# TODO: check if matrix-synapse package is installed (fail if not - it's not
|
||||
# this type's job to install it).
|
||||
|
||||
name=$__object_id
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
case "$os" in
|
||||
debian)
|
||||
synapse_conf_dir='/etc/synapse'
|
||||
synapse_workers_conf_dir="$synapse_conf_dir/workers"
|
||||
|
||||
# Synapse log configuration on debian - default value of config-log
|
||||
# parameter.
|
||||
WORKER_LOG_CONFIG="$synapse_conf_dir/log.yaml"
|
||||
|
||||
# As of writing, debian's matrix-synapse package does not install the
|
||||
# matrix-synapse-worker@.service systemd unit.
|
||||
systemd_worker_service_override=present
|
||||
systemd_worker_service="matrix-synapse-worker@$name"
|
||||
;;
|
||||
*)
|
||||
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "$os" "${__type##*/}" >&2
|
||||
printf "Please contribute an implementation for it if you can.\n" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Type parameters.
|
||||
WORKER_NAME=$__object_id
|
||||
WORKER_APP=$(cat "$__object/parameter/app")
|
||||
WORKER_PORT=$(cat "$__object/parameter/port")
|
||||
WORKER_RESOURCES=$(cat "$__object/parameter/resource")
|
||||
|
||||
export WORKER_APP WORKER_NAME WORKER_PORT
|
||||
|
||||
if [ -f "$__object/parameter/log-config" ]; then
|
||||
WORKER_LOG_CONFIG=$(cat "$__object/parameter/log-config")
|
||||
fi
|
||||
export WORKER_LOG_CONFIG
|
||||
|
||||
WORKER_REPLICATION_HOST=$(cat "$__object/parameter/replication-host")
|
||||
WORKER_REPLICATION_PORT=$(cat "$__object/parameter/replication-port")
|
||||
export WORKER_REPLICATION_HOST WORKER_REPLICATION_PORT
|
||||
|
||||
# Generate and deploy configuration files.
|
||||
mkdir -p "$__object/files"
|
||||
"$__type/files/worker.yaml.sh" > "$__object/files/worker.yaml"
|
||||
|
||||
__directory "$synapse_workers_conf_dir" --parents
|
||||
require="__directory/$synapse_workers_conf_dir" \
|
||||
__file "$synapse_workers_conf_dir/$name.yaml" \
|
||||
--source "$__object/files/worker.yaml" \
|
||||
--mode 0644
|
||||
|
||||
__file "/etc/systemd/systemd/matrix-synapse-worker@.service" \
|
||||
--source "$__type/files/matrix-synapse-worker@.service" \
|
||||
--mode 0644 \
|
||||
--state $systemd_worker_service_override
|
||||
|
||||
# Start service, enable at boot.
|
||||
require="__file/$synapse_workers_conf_dir/$name.yaml \
|
||||
__file/etc/systemd/systemd/matrix-synapse-worker@.service" \
|
||||
__service "$systemd_worker_service" --action start
|
||||
require="__service/$systemd_worker_service" \
|
||||
__start_on_boot "$systemd_worker_service"
|
|
@ -0,0 +1 @@
|
|||
localhost
|
|
@ -0,0 +1 @@
|
|||
9093
|
3
type/__matrix_synapse_worker/parameter/optional
Normal file
3
type/__matrix_synapse_worker/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
|||
replication-host
|
||||
replication-port
|
||||
log-config
|
1
type/__matrix_synapse_worker/parameter/optional_multiple
Normal file
1
type/__matrix_synapse_worker/parameter/optional_multiple
Normal file
|
@ -0,0 +1 @@
|
|||
resource
|
3
type/__matrix_synapse_worker/parameter/required
Normal file
3
type/__matrix_synapse_worker/parameter/required
Normal file
|
@ -0,0 +1,3 @@
|
|||
app
|
||||
name
|
||||
port
|
Loading…
Reference in a new issue