summary refs log tree commit diff
path: root/synapse/app/homeserver.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-10 09:58:33 +0000
committerErik Johnston <erik@matrix.org>2015-03-10 09:58:33 +0000
commitc37eceeb9ef2514237468a7f5e3e6e07d293de16 (patch)
treedc5c1c1e105ac0f341cb471522a79f9f7fa185dd /synapse/app/homeserver.py
parentAdd documentation. When starting via twistd respect soft_file_limit config op... (diff)
downloadsynapse-c37eceeb9ef2514237468a7f5e3e6e07d293de16.tar.xz
Split out the 'run' from 'setup'
Diffstat (limited to '')
-rwxr-xr-xsynapse/app/homeserver.py53
1 files changed, 27 insertions, 26 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 26ef02e3de..e84b9ef5b3 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -296,7 +296,7 @@ def change_resource_limit(soft_file_no):
         logger.warn("Failed to set file limit: %s", e)
 
 
-def setup(config_options, should_run=True):
+def setup(config_options):
     """
     Args:
         config_options_options: The options passed to Synapse. Usually
@@ -380,25 +380,6 @@ def setup(config_options, should_run=True):
     hs.get_datastore().start_profiling()
     hs.get_replication_layer().start_get_pdu_cache()
 
-    if not should_run:
-        return hs
-
-    if config.daemonize:
-        print config.pid_file
-
-        daemon = Daemonize(
-            app="synapse-homeserver",
-            pid=config.pid_file,
-            action=lambda: run(config),
-            auto_close_fds=False,
-            verbose=True,
-            logger=logger,
-        )
-
-        daemon.start()
-    else:
-        run(config)
-
     return hs
 
 
@@ -410,24 +391,44 @@ class SynapseService(service.Service):
         self.config = config
 
     def startService(self):
-        hs = setup(self.config, should_run=False)
+        hs = setup(self.config)
         change_resource_limit(hs.config.soft_file_limit)
 
     def stopService(self):
         return self._port.stopListening()
 
 
-def run(config):
-    with LoggingContext("run"):
-        change_resource_limit(config.soft_file_limit)
+def run(hs):
+
+    def in_thread():
+        with LoggingContext("run"):
+            change_resource_limit(hs.config.soft_file_limit)
 
-        reactor.run()
+            reactor.run()
+
+    if hs.config.daemonize:
+
+        print hs.config.pid_file
+
+        daemon = Daemonize(
+            app="synapse-homeserver",
+            pid=hs.config.pid_file,
+            action=lambda: in_thread(),
+            auto_close_fds=False,
+            verbose=True,
+            logger=logger,
+        )
+
+        daemon.start()
+    else:
+        in_thread(hs.config)
 
 
 def main():
     with LoggingContext("main"):
         check_requirements()
-        setup(sys.argv[1:])
+        hs = setup(sys.argv[1:])
+        run(hs)
 
 
 if __name__ == '__main__':