|
1 | | -# Setup Synapse with Workers and Systemd |
2 | | - |
3 | | -This is a setup for managing synapse with systemd including support for |
4 | | -managing workers. It provides a `matrix-synapse`, as well as a |
5 | | -`matrix-synapse-worker@` service for any workers you require. Additionally to |
6 | | -group the required services it sets up a `matrix.target`. You can use this to |
7 | | -automatically start any bot- or bridge-services. More on this in |
8 | | -[Bots and Bridges](#bots-and-bridges). |
9 | | - |
10 | | -See the folder [system](system) for any service and target files. |
11 | | - |
12 | | -The folder [workers](workers) contains an example configuration for the |
13 | | -`federation_reader` worker. Pay special attention to the name of the |
14 | | -configuration file. In order to work with the `matrix-synapse-worker@.service` |
15 | | -service, it needs to have the exact same name as the worker app. |
16 | | - |
17 | | -This setup expects neither the homeserver nor any workers to fork. Forking is |
18 | | -handled by systemd. |
19 | | - |
20 | | -## Setup |
21 | | - |
22 | | -1. Adjust your matrix configs. Make sure that the worker config files have the |
23 | | -exact same name as the worker app. Compare `matrix-synapse-worker@.service` for |
24 | | -why. You can find an example worker config in the [workers](workers) folder. See |
25 | | -below for relevant settings in the `homeserver.yaml`. |
26 | | -2. Copy the `*.service` and `*.target` files in [system](system) to |
27 | | -`/etc/systemd/system`. |
28 | | -3. `systemctl enable matrix-synapse.service` this adds the homeserver |
29 | | -app to the `matrix.target` |
30 | | -4. *Optional.* `systemctl enable |
31 | | -matrix-synapse-worker@federation_reader.service` this adds the federation_reader |
32 | | -app to the `matrix-synapse.service` |
33 | | -5. *Optional.* Repeat step 4 for any additional workers you require. |
34 | | -6. *Optional.* Add any bots or bridges by enabling them. |
35 | | -7. Start all matrix related services via `systemctl start matrix.target` |
36 | | -8. *Optional.* Enable autostart of all matrix related services on system boot |
37 | | -via `systemctl enable matrix.target` |
38 | | - |
39 | | -## Usage |
40 | | - |
41 | | -After you have setup you can use the following commands to manage your synapse |
42 | | -installation: |
43 | | - |
44 | | -``` |
45 | | -# Start matrix-synapse, all workers and any enabled bots or bridges. |
46 | | -systemctl start matrix.target |
47 | | -
|
48 | | -# Restart matrix-synapse and all workers (not necessarily restarting bots |
49 | | -# or bridges, see "Bots and Bridges") |
50 | | -systemctl restart matrix-synapse.service |
51 | | -
|
52 | | -# Stop matrix-synapse and all workers (not necessarily restarting bots |
53 | | -# or bridges, see "Bots and Bridges") |
54 | | -systemctl stop matrix-synapse.service |
55 | | -
|
56 | | -# Restart a specific worker (i. e. federation_reader), the homeserver is |
57 | | -# unaffected by this. |
58 | | -systemctl restart matrix-synapse-worker@federation_reader.service |
59 | | -
|
60 | | -# Add a new worker (assuming all configs are setup already) |
61 | | -systemctl enable matrix-synapse-worker@federation_writer.service |
62 | | -systemctl restart matrix-synapse.service |
63 | | -``` |
64 | | - |
65 | | -## The Configs |
66 | | - |
67 | | -Make sure the `worker_app` is set in the `homeserver.yaml` and it does not fork. |
68 | | - |
69 | | -``` |
70 | | -worker_app: synapse.app.homeserver |
71 | | -daemonize: false |
72 | | -``` |
73 | | - |
74 | | -None of the workers should fork, as forking is handled by systemd. Hence make |
75 | | -sure this is present in all worker config files. |
76 | | - |
77 | | -``` |
78 | | -worker_daemonize: false |
79 | | -``` |
80 | | - |
81 | | -The config files of all workers are expected to be located in |
82 | | -`/etc/matrix-synapse/workers`. If you want to use a different location you have |
83 | | -to edit the provided `*.service` files accordingly. |
84 | | - |
85 | | -## Bots and Bridges |
86 | | - |
87 | | -Most bots and bridges do not care if the homeserver goes down or is restarted. |
88 | | -Depending on the implementation this may crash them though. So look up the docs |
89 | | -or ask the community of the specific bridge or bot you want to run to make sure |
90 | | -you choose the correct setup. |
91 | | - |
92 | | -Whichever configuration you choose, after the setup the following will enable |
93 | | -automatically starting (and potentially restarting) your bot/bridge with the |
94 | | -`matrix.target`. |
95 | | - |
96 | | -``` |
97 | | -systemctl enable <yourBotOrBridgeName>.service |
98 | | -``` |
99 | | - |
100 | | -**Note** that from an inactive synapse the bots/bridges will only be started with |
101 | | -synapse if you start the `matrix.target`, not if you start the |
102 | | -`matrix-synapse.service`. This is on purpose. Think of `matrix-synapse.service` |
103 | | -as *just* synapse, but `matrix.target` being anything matrix related, including |
104 | | -synapse and any and all enabled bots and bridges. |
105 | | - |
106 | | -### Start with synapse but ignore synapse going down |
107 | | - |
108 | | -If the bridge can handle shutdowns of the homeserver you'll want to install the |
109 | | -service in the `matrix.target` and optionally add a |
110 | | -`After=matrix-synapse.service` dependency to have the bot/bridge start after |
111 | | -synapse on starting everything. |
112 | | - |
113 | | -In this case the service file should look like this. |
114 | | - |
115 | | -``` |
116 | | -[Unit] |
117 | | -# ... |
118 | | -# Optional, this will only ensure that if you start everything, synapse will |
119 | | -# be started before the bot/bridge will be started. |
120 | | -After=matrix-synapse.service |
121 | | -
|
122 | | -[Service] |
123 | | -# ... |
124 | | -
|
125 | | -[Install] |
126 | | -WantedBy=matrix.target |
127 | | -``` |
128 | | - |
129 | | -### Stop/restart when synapse stops/restarts |
130 | | - |
131 | | -If the bridge can't handle shutdowns of the homeserver you'll still want to |
132 | | -install the service in the `matrix.target` but also have to specify the |
133 | | -`After=matrix-synapse.service` *and* `BindsTo=matrix-synapse.service` |
134 | | -dependencies to have the bot/bridge stop/restart with synapse. |
135 | | - |
136 | | -In this case the service file should look like this. |
137 | | - |
138 | | -``` |
139 | | -[Unit] |
140 | | -# ... |
141 | | -# Mandatory |
142 | | -After=matrix-synapse.service |
143 | | -BindsTo=matrix-synapse.service |
144 | | -
|
145 | | -[Service] |
146 | | -# ... |
147 | | -
|
148 | | -[Install] |
149 | | -WantedBy=matrix.target |
150 | | -``` |
| 1 | +The documentation for using systemd to manage synapse workers is now part of |
| 2 | +the main synapse distribution. See [docs/systemd-with-workers](../../docs/systemd-with-workers). |
0 commit comments