summary refs log tree commit diff
path: root/docker/start.py
diff options
context:
space:
mode:
authorMathieu Velten <matmaul@gmail.com>2021-03-16 12:32:18 +0100
committerGitHub <noreply@github.com>2021-03-16 11:32:18 +0000
commitccf1dc51d7a2f261f91ef8d1442a7ddeccc632b8 (patch)
treeccc624692377ec5616f1d84d859479b5f6950df6 /docker/start.py
parentHandle an empty cookie as an invalid macaroon. (#9620) (diff)
downloadsynapse-ccf1dc51d7a2f261f91ef8d1442a7ddeccc632b8.tar.xz
Install jemalloc in docker image (#8553)
Co-authored-by: Will Hunt <willh@matrix.org>
Co-authored-by: Erik Johnston <erik@matrix.org>
Diffstat (limited to '')
-rwxr-xr-xdocker/start.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/docker/start.py b/docker/start.py
index 0d2c590b88..16d6a8208a 100755
--- a/docker/start.py
+++ b/docker/start.py
@@ -3,6 +3,7 @@
 import codecs
 import glob
 import os
+import platform
 import subprocess
 import sys
 
@@ -213,6 +214,13 @@ def main(args, environ):
     if "-m" not in args:
         args = ["-m", synapse_worker] + args
 
+    jemallocpath = "/usr/lib/%s-linux-gnu/libjemalloc.so.2" % (platform.machine(),)
+
+    if os.path.isfile(jemallocpath):
+        environ["LD_PRELOAD"] = jemallocpath
+    else:
+        log("Could not find %s, will not use" % (jemallocpath,))
+
     # 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")
@@ -248,9 +256,9 @@ running with 'migrate_config'. See the README for more details.
     args = ["python"] + args
     if ownership is not None:
         args = ["gosu", ownership] + args
-        os.execv("/usr/sbin/gosu", args)
+        os.execve("/usr/sbin/gosu", args, environ)
     else:
-        os.execv("/usr/local/bin/python", args)
+        os.execve("/usr/local/bin/python", args, environ)
 
 
 if __name__ == "__main__":