This repository was 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
Bash script for creating multiple stream writers #13271
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
51e11a4
Create create-multiple-stream-writers.md
villepeh 650902e
Renaming for distinctness
villepeh 23e9ad9
Create 13271.doc
villepeh 8e3c92d
Remove unnecessary counting
villepeh fadf953
Replace echo with cat. Added more instructions.
villepeh 59cacc7
Fixed typo, added another title
villepeh 8dd8708
Wording
villepeh ae6bd96
Update changelog.d/13271.doc
villepeh 59c7695
Noting that the script needs to be executable
villepeh 6ae37d1
Update contrib/workers-bash-scripts/create-multiple-stream-writers.md
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 hidden or 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 @@ | ||
| Add another `contrib` script to help set up worker processes. Contributed by @villepeh. |
2 changes: 1 addition & 1 deletion
2
...s-bash-scripts/create-multiple-workers.md → ...cripts/create-multiple-generic-workers.md
This file contains hidden or 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
145 changes: 145 additions & 0 deletions
145
contrib/workers-bash-scripts/create-multiple-stream-writers.md
This file contains hidden or 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,145 @@ | ||
| # Creating multiple stream writers with a bash script | ||
|
|
||
| This script creates multiple [stream writer](https://github.com/matrix-org/synapse/blob/develop/docs/workers.md#stream-writers) workers. | ||
|
|
||
| Stream writers require both replication and HTTP listeners. | ||
|
|
||
| It also prints out the example lines for Synapse main configuration file. | ||
|
|
||
| Remember to route necessary endpoints directly to a worker associated with it. | ||
|
|
||
| If you run the script as-is, it will create workers with the replication listener starting from port 8034 and another, regular http listener starting from 8044. If you don't need all of the stream writers listed in the script, just remove them from the ```STREAM_WRITERS``` array. | ||
|
|
||
| ```sh | ||
| #!/bin/bash | ||
|
|
||
| # Start with these replication and http ports. | ||
| # The script loop starts with the exact port and then increments it by one. | ||
| REP_START_PORT=8034 | ||
| HTTP_START_PORT=8044 | ||
|
|
||
| # Stream writer workers to generate. Feel free to add or remove them as you wish. | ||
| # Event persister ("events") isn't included here as it does not require its | ||
| # own HTTP listener. | ||
|
|
||
| STREAM_WRITERS+=( "presence" "typing" "receipts" "to_device" "account_data" ) | ||
|
|
||
| NUM_WRITERS=$(expr ${#STREAM_WRITERS[@]}) | ||
|
|
||
| i=0 | ||
|
|
||
| while [ $i -lt "$NUM_WRITERS" ] | ||
| do | ||
| cat << EOF > ${STREAM_WRITERS[$i]}_stream_writer.yaml | ||
| worker_app: synapse.app.generic_worker | ||
| worker_name: ${STREAM_WRITERS[$i]}_stream_writer | ||
|
|
||
| # The replication listener on the main synapse process. | ||
| worker_replication_host: 127.0.0.1 | ||
| worker_replication_http_port: 9093 | ||
|
|
||
| worker_listeners: | ||
| - type: http | ||
| port: $(expr $REP_START_PORT + $i) | ||
| resources: | ||
| - names: [replication] | ||
|
|
||
| - type: http | ||
| port: $(expr $HTTP_START_PORT + $i) | ||
| resources: | ||
| - names: [client] | ||
|
|
||
| worker_log_config: /etc/matrix-synapse/stream-writer-log.yaml | ||
| EOF | ||
| HOMESERVER_YAML_INSTANCE_MAP+=$" ${STREAM_WRITERS[$i]}_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: $(expr $REP_START_PORT + $i) | ||
| " | ||
|
|
||
| HOMESERVER_YAML_STREAM_WRITERS+=$" ${STREAM_WRITERS[$i]}: ${STREAM_WRITERS[$i]}_stream_writer | ||
| " | ||
|
|
||
| ((i++)) | ||
| done | ||
|
|
||
| cat << EXAMPLECONFIG | ||
| # Add these lines to your homeserver.yaml. | ||
| # Don't forget to configure your reverse proxy and | ||
| # necessary endpoints to their respective worker. | ||
|
|
||
| # See https://github.com/matrix-org/synapse/blob/develop/docs/workers.md | ||
| # for more information. | ||
|
|
||
| # Remember: Under NO circumstances should the replication | ||
| # listener be exposed to the public internet; | ||
| # it has no authentication and is unencrypted. | ||
|
|
||
| instance_map: | ||
| $HOMESERVER_YAML_INSTANCE_MAP | ||
| stream_writers: | ||
| $HOMESERVER_YAML_STREAM_WRITERS | ||
| EXAMPLECONFIG | ||
| ``` | ||
|
|
||
| Copy the code above save it to a file ```create_stream_writers.sh``` (for example). | ||
|
|
||
| Make the script executable by running ```chmod +x create_stream_writers.sh```. | ||
|
|
||
| ## Run the script to create workers and print out a sample configuration | ||
|
|
||
| Simply run the script to create YAML files in the current folder and print out the required configuration for ```homeserver.yaml```. | ||
|
|
||
| ```console | ||
| $ ./create_stream_writers.sh | ||
|
|
||
| # Add these lines to your homeserver.yaml. | ||
| # Don't forget to configure your reverse proxy and | ||
| # necessary endpoints to their respective worker. | ||
|
|
||
| # See https://github.com/matrix-org/synapse/blob/develop/docs/workers.md | ||
| # for more information | ||
|
|
||
| # Remember: Under NO circumstances should the replication | ||
| # listener be exposed to the public internet; | ||
| # it has no authentication and is unencrypted. | ||
|
|
||
| instance_map: | ||
| presence_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: 8034 | ||
| typing_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: 8035 | ||
| receipts_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: 8036 | ||
| to_device_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: 8037 | ||
| account_data_stream_writer: | ||
| host: 127.0.0.1 | ||
| port: 8038 | ||
|
|
||
| stream_writers: | ||
| presence: presence_stream_writer | ||
| typing: typing_stream_writer | ||
| receipts: receipts_stream_writer | ||
| to_device: to_device_stream_writer | ||
| account_data: account_data_stream_writer | ||
| ``` | ||
|
|
||
| Simply copy-and-paste the output to an appropriate place in your Synapse main configuration file. | ||
|
|
||
| ## Write directly to Synapse configuration file | ||
|
|
||
| You could also write the output directly to homeserver main configuration file. **This, however, is not recommended** as even a small typo (such as replacing >> with >) can erase the entire ```homeserver.yaml```. | ||
|
|
||
| If you do this, back up your original configuration file first: | ||
|
|
||
| ```console | ||
| # Back up homeserver.yaml first | ||
| cp /etc/matrix-synapse/homeserver.yaml /etc/matrix-synapse/homeserver.yaml.bak | ||
|
|
||
| # Create workers and write output to your homeserver.yaml | ||
| ./create_stream_writers.sh >> /etc/matrix-synapse/homeserver.yaml | ||
| ``` | ||
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.
Uh oh!
There was an error while loading. Please reload this page.