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

Commit c37ecee

Browse files
committed
Split out the 'run' from 'setup'
1 parent b8a6692 commit c37ecee

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

synapse/app/homeserver.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def change_resource_limit(soft_file_no):
296296
logger.warn("Failed to set file limit: %s", e)
297297

298298

299-
def setup(config_options, should_run=True):
299+
def setup(config_options):
300300
"""
301301
Args:
302302
config_options_options: The options passed to Synapse. Usually
@@ -380,25 +380,6 @@ def setup(config_options, should_run=True):
380380
hs.get_datastore().start_profiling()
381381
hs.get_replication_layer().start_get_pdu_cache()
382382

383-
if not should_run:
384-
return hs
385-
386-
if config.daemonize:
387-
print config.pid_file
388-
389-
daemon = Daemonize(
390-
app="synapse-homeserver",
391-
pid=config.pid_file,
392-
action=lambda: run(config),
393-
auto_close_fds=False,
394-
verbose=True,
395-
logger=logger,
396-
)
397-
398-
daemon.start()
399-
else:
400-
run(config)
401-
402383
return hs
403384

404385

@@ -410,24 +391,44 @@ def __init__(self, config):
410391
self.config = config
411392

412393
def startService(self):
413-
hs = setup(self.config, should_run=False)
394+
hs = setup(self.config)
414395
change_resource_limit(hs.config.soft_file_limit)
415396

416397
def stopService(self):
417398
return self._port.stopListening()
418399

419400

420-
def run(config):
421-
with LoggingContext("run"):
422-
change_resource_limit(config.soft_file_limit)
401+
def run(hs):
402+
403+
def in_thread():
404+
with LoggingContext("run"):
405+
change_resource_limit(hs.config.soft_file_limit)
423406

424-
reactor.run()
407+
reactor.run()
408+
409+
if hs.config.daemonize:
410+
411+
print hs.config.pid_file
412+
413+
daemon = Daemonize(
414+
app="synapse-homeserver",
415+
pid=hs.config.pid_file,
416+
action=lambda: in_thread(),
417+
auto_close_fds=False,
418+
verbose=True,
419+
logger=logger,
420+
)
421+
422+
daemon.start()
423+
else:
424+
in_thread(hs.config)
425425

426426

427427
def main():
428428
with LoggingContext("main"):
429429
check_requirements()
430-
setup(sys.argv[1:])
430+
hs = setup(sys.argv[1:])
431+
run(hs)
431432

432433

433434
if __name__ == '__main__':

0 commit comments

Comments
 (0)