diff options
Diffstat (limited to 'docker/generate_shared_worker_config.py')
-rw-r--r-- | docker/generate_shared_worker_config.py | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/docker/generate_shared_worker_config.py b/docker/generate_shared_worker_config.py deleted file mode 100644 index 755a737344..0000000000 --- a/docker/generate_shared_worker_config.py +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright 2020 The Matrix.org Foundation C.I.C. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script reads environment variables and generates a shared Synapse worker, -# nginx and supervisord configs depending on the workers requested - -import os -import sys - - -def main(args, environ): - """Read the desired list of workers from environment variables and generate - shared homeserver, nginx and supervisord configs. - - Args: - environ: _Environ[str] - """ - # The contents of this string will be appended to the one generated by - # the homeserver, and is intended mainly for disabling functionality on the main - # when certain workers are spun up - homeserver_config = "" - - # The contents of this string will be append to the base supervisord config - supervisord_config = "" - - # An nginx site config. Will live in /etc/nginx/conf.d - nginx_config_template_header = """ - server { - listen 80; - listen [::]:80; - - # For the federation port - listen 8448 default_server; - listen [::]:8448 default_server; - - server_name localhost; - """ - nginx_config_body = "" - nginx_config_template_end = """ - # Send all other traffic to the main process - location ~* ^(\/_matrix|\/_synapse) { - proxy_pass http://localhost:8008; - proxy_set_header X-Forwarded-For $remote_addr; - - # TODO: Can we move this to the default nginx.conf so all locations are - # affected? - # - # Nginx by default only allows file uploads up to 1M in size - # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml - client_max_body_size 50M; - } - } - """ - - # Read desired worker configuration from environment - worker_types = environ.get("SYNAPSE_WORKERS") - worker_types = worker_types.split(",") - - for worker_type in worker_types: - if worker_type == "pusher": - # Disable push handling from the main process - homeserver_config += """ - start_pushers: false - """ - - # Enable the pusher worker in supervisord - supervisord_config += """ - """ - - # This worker does not handle any REST endpoints - - elif worker_type == "appservice": - # Disable appservice traffic sending from the main process - homeserver_config += """ - notify_appservices: false - """ - - # Enable the pusher worker in supervisord - supervisord_config += """ - [program:synapse_user_dir] - command=/usr/local/bin/python -m synapse.app.user_dir \ - --config-path=/config/homeserver.yaml \ - --config-path=/config/workers/user_dir.yaml - autorestart=unexpected - exitcodes=0 - """ - - # This worker does not handle any REST endpoints - - elif worker_type == "user_dir": - # Disable user directory updates on the main process - homeserver_config += """ - update_user_directory: false - """ - - # Enable the user directory worker in supervisord - supervisord_config += """ - [program:synapse_user_dir] - command=/usr/local/bin/python -m synapse.app.user_dir \ - --config-path=/config/homeserver.yaml \ - --config-path=/config/workers/user_dir.yaml - autorestart=unexpected - exitcodes=0 - """ - - # Route user directory requests to this worker - nginx_config_body += """ - location ~* ^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$ { - proxy_pass http://localhost:8010; - proxy_set_header X-Forwarded-For $remote_addr; - } - """ - - # Write out the config files - - # Main homeserver config - with open("/config/main.yaml", "a") as f: - f.write(homeserver_config) - - # Nginx config - with open("/config/nginx.conf", "w") as f: - f.write(nginx_config_template_header) - f.write(nginx_config_body) - f.write(nginx_config_template_end) - - # Supervisord config - with open("/config/supervisord.conf", "a") as f: - f.write(supervisord_config) - - -if __name__ == "__main__": - main(sys.argv, os.environ) |