This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make systemd-with-workers doc official #7234
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f16437
Make systemd-with-workers doc official
richvdh 618dac8
a few updates
richvdh d71720c
Remove redundant "AllowIsolate"
richvdh 7ed3c55
Update contrib/systemd-with-workers/README.md
richvdh b88fd72
fix link, again
richvdh 3accd6f
missing punctuation
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update the contributed documentation on managing synapse workers with systemd, and bring it into the core distribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,2 @@ | ||
# Setup Synapse with Workers and Systemd | ||
|
||
This is a setup for managing synapse with systemd including support for | ||
managing workers. It provides a `matrix-synapse`, as well as a | ||
`matrix-synapse-worker@` service for any workers you require. Additionally to | ||
group the required services it sets up a `matrix.target`. You can use this to | ||
automatically start any bot- or bridge-services. More on this in | ||
[Bots and Bridges](#bots-and-bridges). | ||
|
||
See the folder [system](system) for any service and target files. | ||
|
||
The folder [workers](workers) contains an example configuration for the | ||
`federation_reader` worker. Pay special attention to the name of the | ||
configuration file. In order to work with the `[email protected]` | ||
service, it needs to have the exact same name as the worker app. | ||
|
||
This setup expects neither the homeserver nor any workers to fork. Forking is | ||
handled by systemd. | ||
|
||
## Setup | ||
|
||
1. Adjust your matrix configs. Make sure that the worker config files have the | ||
exact same name as the worker app. Compare `[email protected]` for | ||
why. You can find an example worker config in the [workers](workers) folder. See | ||
below for relevant settings in the `homeserver.yaml`. | ||
2. Copy the `*.service` and `*.target` files in [system](system) to | ||
`/etc/systemd/system`. | ||
3. `systemctl enable matrix-synapse.service` this adds the homeserver | ||
app to the `matrix.target` | ||
4. *Optional.* `systemctl enable | ||
matrix-synapse-worker@federation_reader.service` this adds the federation_reader | ||
app to the `matrix-synapse.service` | ||
5. *Optional.* Repeat step 4 for any additional workers you require. | ||
6. *Optional.* Add any bots or bridges by enabling them. | ||
7. Start all matrix related services via `systemctl start matrix.target` | ||
8. *Optional.* Enable autostart of all matrix related services on system boot | ||
via `systemctl enable matrix.target` | ||
|
||
## Usage | ||
|
||
After you have setup you can use the following commands to manage your synapse | ||
installation: | ||
|
||
``` | ||
# Start matrix-synapse, all workers and any enabled bots or bridges. | ||
systemctl start matrix.target | ||
|
||
# Restart matrix-synapse and all workers (not necessarily restarting bots | ||
# or bridges, see "Bots and Bridges") | ||
systemctl restart matrix-synapse.service | ||
|
||
# Stop matrix-synapse and all workers (not necessarily restarting bots | ||
# or bridges, see "Bots and Bridges") | ||
systemctl stop matrix-synapse.service | ||
|
||
# Restart a specific worker (i. e. federation_reader), the homeserver is | ||
# unaffected by this. | ||
systemctl restart matrix-synapse-worker@federation_reader.service | ||
|
||
# Add a new worker (assuming all configs are setup already) | ||
systemctl enable matrix-synapse-worker@federation_writer.service | ||
systemctl restart matrix-synapse.service | ||
``` | ||
|
||
## The Configs | ||
|
||
Make sure the `worker_app` is set in the `homeserver.yaml` and it does not fork. | ||
|
||
``` | ||
worker_app: synapse.app.homeserver | ||
daemonize: false | ||
``` | ||
|
||
None of the workers should fork, as forking is handled by systemd. Hence make | ||
sure this is present in all worker config files. | ||
|
||
``` | ||
worker_daemonize: false | ||
``` | ||
|
||
The config files of all workers are expected to be located in | ||
`/etc/matrix-synapse/workers`. If you want to use a different location you have | ||
to edit the provided `*.service` files accordingly. | ||
|
||
## Bots and Bridges | ||
|
||
Most bots and bridges do not care if the homeserver goes down or is restarted. | ||
Depending on the implementation this may crash them though. So look up the docs | ||
or ask the community of the specific bridge or bot you want to run to make sure | ||
you choose the correct setup. | ||
|
||
Whichever configuration you choose, after the setup the following will enable | ||
automatically starting (and potentially restarting) your bot/bridge with the | ||
`matrix.target`. | ||
|
||
``` | ||
systemctl enable <yourBotOrBridgeName>.service | ||
``` | ||
|
||
**Note** that from an inactive synapse the bots/bridges will only be started with | ||
synapse if you start the `matrix.target`, not if you start the | ||
`matrix-synapse.service`. This is on purpose. Think of `matrix-synapse.service` | ||
as *just* synapse, but `matrix.target` being anything matrix related, including | ||
synapse and any and all enabled bots and bridges. | ||
|
||
### Start with synapse but ignore synapse going down | ||
|
||
If the bridge can handle shutdowns of the homeserver you'll want to install the | ||
service in the `matrix.target` and optionally add a | ||
`After=matrix-synapse.service` dependency to have the bot/bridge start after | ||
synapse on starting everything. | ||
|
||
In this case the service file should look like this. | ||
|
||
``` | ||
[Unit] | ||
# ... | ||
# Optional, this will only ensure that if you start everything, synapse will | ||
# be started before the bot/bridge will be started. | ||
After=matrix-synapse.service | ||
|
||
[Service] | ||
# ... | ||
|
||
[Install] | ||
WantedBy=matrix.target | ||
``` | ||
|
||
### Stop/restart when synapse stops/restarts | ||
|
||
If the bridge can't handle shutdowns of the homeserver you'll still want to | ||
install the service in the `matrix.target` but also have to specify the | ||
`After=matrix-synapse.service` *and* `BindsTo=matrix-synapse.service` | ||
dependencies to have the bot/bridge stop/restart with synapse. | ||
|
||
In this case the service file should look like this. | ||
|
||
``` | ||
[Unit] | ||
# ... | ||
# Mandatory | ||
After=matrix-synapse.service | ||
BindsTo=matrix-synapse.service | ||
|
||
[Service] | ||
# ... | ||
|
||
[Install] | ||
WantedBy=matrix.target | ||
``` | ||
The documentation for using systemd to manage synapse workers is now part of | ||
the main synapse distribution. See [docs/systemd-with-workers](../../docs/systemd-with-workers). |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Setting up Synapse with Workers and Systemd | ||
|
||
This is a setup for managing synapse with systemd, including support for | ||
managing workers. It provides a `matrix-synapse` service for the master, as | ||
well as a `matrix-synapse-worker@` service template for any workers you | ||
require. Additionally, to group the required services, it sets up a | ||
`matrix-synapse.target`. | ||
|
||
See the folder [system](system) for the systemd unit files. | ||
|
||
The folder [workers](workers) contains an example configuration for the | ||
`federation_reader` worker. | ||
|
||
## Synapse configuration files | ||
|
||
See [workers.md](../workers.md) for information on how to set up the | ||
configuration files and reverse-proxy correctly. You can find an example worker | ||
config in the [workers](workers) folder. | ||
|
||
Systemd manages daemonization itself, so ensure that none of the configuration | ||
files set either `daemonize` or `worker_daemonize`. | ||
|
||
The config files of all workers are expected to be located in | ||
`/etc/matrix-synapse/workers`. If you want to use a different location, edit | ||
the provided `*.service` files accordingly. | ||
|
||
There is no need for a separate configuration file for the master process. | ||
|
||
## Set up | ||
|
||
1. Adjust synapse configuration files as above. | ||
1. Copy the `*.service` and `*.target` files in [system](system) to | ||
`/etc/systemd/system`. | ||
1. Run `systemctl deamon-reload` to tell systemd to load the new unit files. | ||
1. Run `systemctl enable matrix-synapse.service`. This will configure the | ||
synapse master process to be started as part of the `matrix-synapse.target` | ||
target. | ||
1. For each worker process to be enabled, run `systemctl enable | ||
matrix-synapse-worker@<worker_name>.service`. For each `<worker_name>`, there | ||
should be a corresponding configuration file | ||
`/etc/matrix-synapse/workers/<worker_name>.yaml`. | ||
1. Start all the synapse processes with `systemctl start matrix-synapse.target`. | ||
1. Tell systemd to start synapse on boot with `systemctl enable matrix-synapse.target`/ | ||
|
||
## Usage | ||
|
||
Once the services are correctly set up, you can use the following commands | ||
to manage your synapse installation: | ||
|
||
```sh | ||
# Restart Synapse master and all workers | ||
systemctl restart matrix-synapse.target | ||
|
||
# Stop Synapse and all workers | ||
systemctl stop matrix-synapse.target | ||
|
||
# Restart the master alone | ||
systemctl start matrix-synapse.service | ||
|
||
# Restart a specific worker (eg. federation_reader); the master is | ||
# unaffected by this. | ||
systemctl restart matrix-synapse-worker@federation_reader.service | ||
|
||
# Add a new worker (assuming all configs are set up already) | ||
systemctl enable matrix-synapse-worker@federation_writer.service | ||
systemctl restart matrix-synapse.target | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[Unit] | ||
Description=Synapse %i | ||
|
||
# This service should be restarted when the synapse target is restarted. | ||
PartOf=matrix-synapse.target | ||
|
||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Unit] | ||
Description=Synapse parent target | ||
After=network.target | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
synapse.app.generic_worker
the new catch all for all workers? becauseof spantaleev/matrix-docker-ansible-deploy#456 ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. ppsst.. @erikjohnston .. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closed PRs are not a good place to ask questions.