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

Commit a51d866

Browse files
committed
Merge pull request #5563 from matrix-org/rav/docker/data_dir
2 parents d7d827f + b1b8a24 commit a51d866

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

changelog.d/5563.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Docker: Use a sensible location for data files when generating a config file.

docker/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,14 @@ docker run -d --name synapse \
179179
-e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml \
180180
matrixdotorg/synapse:latest
181181
```
182+
183+
The following environment variables are supported in this mode:
184+
185+
* `SYNAPSE_SERVER_NAME` (mandatory): the server public hostname.
186+
* `SYNAPSE_REPORT_STATS` (mandatory, `yes` or `no`): whether to enable
187+
anonymous statistics reporting.
188+
* `SYNAPSE_CONFIG_PATH` (mandatory): path to the file to be generated.
189+
* `SYNAPSE_DATA_DIR`: where the generated config will put persistent data
190+
such as the datatase and media store. Defaults to `/data`.
191+
* `UID`, `GID`: the user id and group id to use for creating the data
192+
directories. Defaults to `991`, `991`.

docker/start.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,24 @@ def generate_config_from_template(environ, ownership):
122122
return config_path
123123

124124

125-
def run_generate_config(environ):
125+
def run_generate_config(environ, ownership):
126126
"""Run synapse with a --generate-config param to generate a template config file
127127
128128
Args:
129-
environ (dict): environment dictionary
129+
environ (dict): env var dict
130+
ownership (str): "userid:groupid" arg for chmod
130131
131132
Never returns.
132133
"""
133134
for v in ("SYNAPSE_SERVER_NAME", "SYNAPSE_REPORT_STATS", "SYNAPSE_CONFIG_PATH"):
134135
if v not in environ:
135136
error("Environment variable '%s' is mandatory in `generate` mode." % (v,))
136137

138+
data_dir = environ.get("SYNAPSE_DATA_DIR", "/data")
139+
140+
# make sure that synapse has perms to write to the data dir.
141+
subprocess.check_output(["chown", ownership, data_dir])
142+
137143
args = [
138144
"python",
139145
"-m",
@@ -144,18 +150,21 @@ def run_generate_config(environ):
144150
environ["SYNAPSE_REPORT_STATS"],
145151
"--config-path",
146152
environ["SYNAPSE_CONFIG_PATH"],
153+
"--data-directory",
154+
data_dir,
147155
"--generate-config",
148156
]
157+
# log("running %s" % (args, ))
149158
os.execv("/usr/local/bin/python", args)
150159

151160

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

156-
# In generate mode, generate a configuration, missing keys, then exit
165+
# In generate mode, generate a configuration and missing keys, then exit
157166
if mode == "generate":
158-
return run_generate_config(environ)
167+
return run_generate_config(environ, ownership)
159168

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

0 commit comments

Comments
 (0)