summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
Diffstat (limited to 'synapse')
-rwxr-xr-xsynapse/app/homeserver.py21
-rw-r--r--synapse/storage/_base.py1
2 files changed, 19 insertions, 3 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index afe3d19760..9b23c58abe 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -21,6 +21,7 @@ from synapse.server import HomeServer
 from synapse.python_dependencies import check_requirements
 
 from twisted.internet import reactor
+from twisted.application import service
 from twisted.enterprise import adbapi
 from twisted.web.resource import Resource
 from twisted.web.static import File
@@ -193,10 +194,10 @@ class SynapseHomeServer(HomeServer):
             logger.info("Synapse now listening on port %d", unsecure_port)
 
 
-def setup():
+def setup(config_options, should_run=True):
     config = HomeServerConfig.load_config(
         "Synapse Homeserver",
-        sys.argv[1:],
+        config_options,
         generate_section="Homeserver"
     )
 
@@ -268,6 +269,9 @@ def setup():
         bind_port = None
     hs.start_listening(bind_port, config.unsecure_port)
 
+    if not should_run:
+        return
+
     if config.daemonize:
         print config.pid_file
         daemon = Daemonize(
@@ -284,6 +288,17 @@ def setup():
         reactor.run()
 
 
+class SynapseService(service.Service):
+    def __init__(self, config):
+        self.config = config
+
+    def startService(self):
+        setup(self.config, should_run=False)
+
+    def stopService(self):
+        return self._port.stopListening()
+
+
 def run():
     with LoggingContext("run"):
         reactor.run()
@@ -292,7 +307,7 @@ def run():
 def main():
     with LoggingContext("main"):
         check_requirements()
-        setup()
+        setup(sys.argv[1:])
 
 
 if __name__ == '__main__':
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index f660fc6eaf..ce63f12008 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -95,6 +95,7 @@ class SQLBaseStore(object):
                 current_context.copy_to(context)
                 start = time.time() * 1000
                 txn_id = SQLBaseStore._TXN_ID
+                SQLBaseStore._TXN_ID += 1
 
                 # We don't really need these to be unique, so lets stop it from
                 # growing really large.