Split out the 'run' from 'setup'

pull/105/head
Erik Johnston 2015-03-10 09:58:33 +00:00
parent b8a6692657
commit c37eceeb9e
1 changed files with 27 additions and 26 deletions

View File

@ -296,7 +296,7 @@ def change_resource_limit(soft_file_no):
logger.warn("Failed to set file limit: %s", e) logger.warn("Failed to set file limit: %s", e)
def setup(config_options, should_run=True): def setup(config_options):
""" """
Args: Args:
config_options_options: The options passed to Synapse. Usually 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_datastore().start_profiling()
hs.get_replication_layer().start_get_pdu_cache() 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 return hs
@ -410,24 +391,44 @@ class SynapseService(service.Service):
self.config = config self.config = config
def startService(self): def startService(self):
hs = setup(self.config, should_run=False) hs = setup(self.config)
change_resource_limit(hs.config.soft_file_limit) change_resource_limit(hs.config.soft_file_limit)
def stopService(self): def stopService(self):
return self._port.stopListening() return self._port.stopListening()
def run(config): def run(hs):
with LoggingContext("run"):
change_resource_limit(config.soft_file_limit)
reactor.run() def in_thread():
with LoggingContext("run"):
change_resource_limit(hs.config.soft_file_limit)
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(): def main():
with LoggingContext("main"): with LoggingContext("main"):
check_requirements() check_requirements()
setup(sys.argv[1:]) hs = setup(sys.argv[1:])
run(hs)
if __name__ == '__main__': if __name__ == '__main__':