0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-13 21:03:25 +01:00

Docker: support passing additional commandline args to synapse (#8390)

This commit is contained in:
Samuel Philipp 2020-10-11 21:51:11 +02:00 committed by GitHub
parent d35a451399
commit 6905f5751a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 18 deletions

1
changelog.d/8390.docker Normal file
View file

@ -0,0 +1 @@
Add support for passing commandline args to the synapse process. Contributed by @samuel-p.

View file

@ -83,7 +83,7 @@ docker logs synapse
If all is well, you should now be able to connect to http://localhost:8008 and If all is well, you should now be able to connect to http://localhost:8008 and
see a confirmation message. see a confirmation message.
The following environment variables are supported in run mode: The following environment variables are supported in `run` mode:
* `SYNAPSE_CONFIG_DIR`: where additional config files are stored. Defaults to * `SYNAPSE_CONFIG_DIR`: where additional config files are stored. Defaults to
`/data`. `/data`.
@ -94,6 +94,20 @@ The following environment variables are supported in run mode:
* `UID`, `GID`: the user and group id to run Synapse as. Defaults to `991`, `991`. * `UID`, `GID`: the user and group id to run Synapse as. Defaults to `991`, `991`.
* `TZ`: the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) the container will run with. Defaults to `UTC`. * `TZ`: the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) the container will run with. Defaults to `UTC`.
For more complex setups (e.g. for workers) you can also pass your args directly to synapse using `run` mode. For example like this:
```
docker run -d --name synapse \
--mount type=volume,src=synapse-data,dst=/data \
-p 8008:8008 \
matrixdotorg/synapse:latest run \
-m synapse.app.generic_worker \
--config-path=/data/homeserver.yaml \
--config-path=/data/generic_worker.yaml
```
If you do not provide `-m`, the value of the `SYNAPSE_WORKER` environment variable is used. If you do not provide at least one `--config-path` or `-c`, the value of the `SYNAPSE_CONFIG_PATH` environment variable is used instead.
## Generating an (admin) user ## Generating an (admin) user
After synapse is running, you may wish to create a user via `register_new_matrix_user`. After synapse is running, you may wish to create a user via `register_new_matrix_user`.

View file

@ -179,7 +179,7 @@ def run_generate_config(environ, ownership):
def main(args, environ): def main(args, environ):
mode = args[1] if len(args) > 1 else None mode = args[1] if len(args) > 1 else "run"
desired_uid = int(environ.get("UID", "991")) desired_uid = int(environ.get("UID", "991"))
desired_gid = int(environ.get("GID", "991")) desired_gid = int(environ.get("GID", "991"))
synapse_worker = environ.get("SYNAPSE_WORKER", "synapse.app.homeserver") synapse_worker = environ.get("SYNAPSE_WORKER", "synapse.app.homeserver")
@ -205,11 +205,20 @@ def main(args, environ):
config_dir, config_path, environ, ownership config_dir, config_path, environ, ownership
) )
if mode is not None: if mode != "run":
error("Unknown execution mode '%s'" % (mode,)) error("Unknown execution mode '%s'" % (mode,))
args = args[2:]
if "-m" not in args:
args = ["-m", synapse_worker] + args
# if there are no config files passed to synapse, try adding the default file
if not any(p.startswith("--config-path") or p.startswith("-c") for p in args):
config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data") config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
config_path = environ.get("SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml") config_path = environ.get(
"SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml"
)
if not os.path.exists(config_path): if not os.path.exists(config_path):
if "SYNAPSE_SERVER_NAME" in environ: if "SYNAPSE_SERVER_NAME" in environ:
@ -232,9 +241,11 @@ running with 'migrate_config'. See the README for more details.
% (config_path,) % (config_path,)
) )
log("Starting synapse with config file " + config_path) args += ["--config-path", config_path]
args = ["python", "-m", synapse_worker, "--config-path", config_path] log("Starting synapse with args " + " ".join(args))
args = ["python"] + args
if ownership is not None: if ownership is not None:
args = ["gosu", ownership] + args args = ["gosu", ownership] + args
os.execv("/usr/sbin/gosu", args) os.execv("/usr/sbin/gosu", args)