Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5563 from matrix-org/rav/docker/data_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 14, 2020
2 parents d7d827f + b1b8a24 commit a51d866
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/5563.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Docker: Use a sensible location for data files when generating a config file.
11 changes: 11 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ docker run -d --name synapse \
-e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml \
matrixdotorg/synapse:latest
```

The following environment variables are supported in this mode:

* `SYNAPSE_SERVER_NAME` (mandatory): the server public hostname.
* `SYNAPSE_REPORT_STATS` (mandatory, `yes` or `no`): whether to enable
anonymous statistics reporting.
* `SYNAPSE_CONFIG_PATH` (mandatory): path to the file to be generated.
* `SYNAPSE_DATA_DIR`: where the generated config will put persistent data
such as the datatase and media store. Defaults to `/data`.
* `UID`, `GID`: the user id and group id to use for creating the data
directories. Defaults to `991`, `991`.
17 changes: 13 additions & 4 deletions docker/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,24 @@ def generate_config_from_template(environ, ownership):
return config_path


def run_generate_config(environ):
def run_generate_config(environ, ownership):
"""Run synapse with a --generate-config param to generate a template config file
Args:
environ (dict): environment dictionary
environ (dict): env var dict
ownership (str): "userid:groupid" arg for chmod
Never returns.
"""
for v in ("SYNAPSE_SERVER_NAME", "SYNAPSE_REPORT_STATS", "SYNAPSE_CONFIG_PATH"):
if v not in environ:
error("Environment variable '%s' is mandatory in `generate` mode." % (v,))

data_dir = environ.get("SYNAPSE_DATA_DIR", "/data")

# make sure that synapse has perms to write to the data dir.
subprocess.check_output(["chown", ownership, data_dir])

args = [
"python",
"-m",
Expand All @@ -144,18 +150,21 @@ def run_generate_config(environ):
environ["SYNAPSE_REPORT_STATS"],
"--config-path",
environ["SYNAPSE_CONFIG_PATH"],
"--data-directory",
data_dir,
"--generate-config",
]
# log("running %s" % (args, ))
os.execv("/usr/local/bin/python", args)


def main(args, environ):
mode = args[1] if len(args) > 1 else None
ownership = "{}:{}".format(environ.get("UID", 991), environ.get("GID", 991))

# In generate mode, generate a configuration, missing keys, then exit
# In generate mode, generate a configuration and missing keys, then exit
if mode == "generate":
return run_generate_config(environ)
return run_generate_config(environ, ownership)

# In normal mode, generate missing keys if any, then run synapse
if "SYNAPSE_CONFIG_PATH" in environ:
Expand Down

0 comments on commit a51d866

Please sign in to comment.