diff options
author | drebs <drebs@riseup.net> | 2017-11-20 10:55:30 -0200 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2017-11-20 11:20:53 -0200 |
commit | 642541e2ab7f0c7eacd45ba013221e43db19fd7f (patch) | |
tree | 5c14c5a6325dab0beb428742032bb0c56fb52df2 | |
parent | e4d594fca9fb42854bdc167aada9847acf6c231f (diff) |
[bug] use reactor.stop() to exit when server startup checks fail
Our current use of sys.exit(20) to stop the server when startup checks
fail affects logging in a bad way. This commit uses a system event
trigger to exit with the desired status code when startup checks fail.
Closes: #8996
-rw-r--r-- | src/leap/soledad/server/app.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/leap/soledad/server/app.py b/src/leap/soledad/server/app.py index 4129ec95..725b1383 100644 --- a/src/leap/soledad/server/app.py +++ b/src/leap/soledad/server/app.py @@ -21,6 +21,7 @@ import sys import os from twisted.application import service, strports +from twisted.internet import reactor from twisted.web import server from leap.soledad.common.couch.check import check_schema_versions @@ -32,6 +33,12 @@ from leap.soledad.server import get_config logger = getLogger(__name__) +def _exit(status): + reactor.addSystemEventTrigger( + 'after', 'shutdown', sys.exit, status) + reactor.stop() + + # # necessary checks # @@ -39,11 +46,11 @@ logger = getLogger(__name__) def check_env(local_port, public_port): if local_port == public_port: logger.error("LOCAL_SERVICES_PORT and HTTPS_PORT can't be the same!") - sys.exit(20) + _exit(20) if public_port is None and not os.getenv('DEBUG_SERVER'): logger.error("HTTPS_PORT env var is required to be set!") - sys.exit(20) + _exit(20) def check_conf(conf): @@ -58,7 +65,7 @@ def check_conf(conf): ** REFUSING TO START. Please double check your configuration. ** """ logger.error(message % path) - sys.exit(20) + _exit(20) # |