diff --git a/changelog.d/19131.misc b/changelog.d/19131.misc new file mode 100644 index 000000000..cb1fb8f02 --- /dev/null +++ b/changelog.d/19131.misc @@ -0,0 +1 @@ +Refactor and align app entrypoints (avoid `exit(1)` in our composable functions). diff --git a/synapse/app/admin_cmd.py b/synapse/app/admin_cmd.py index dac603de8..193482b7f 100644 --- a/synapse/app/admin_cmd.py +++ b/synapse/app/admin_cmd.py @@ -369,6 +369,7 @@ async def start(admin_command_server: AdminCmdServer, args: argparse.Namespace) def main() -> None: homeserver_config, args = load_config(sys.argv[1:]) with LoggingContext(name="main", server_name=homeserver_config.server.server_name): + # Initialize and setup the homeserver admin_command_server = create_homeserver(homeserver_config) setup(admin_command_server) diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index a1dde368d..0a4abd183 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -450,16 +450,21 @@ def main() -> None: # Create a logging context as soon as possible so we can start associating # everything with this homeserver. with LoggingContext(name="main", server_name=homeserver_config.server.server_name): - # redirect stdio to the logs, if configured. - if not homeserver_config.logging.no_redirect_stdio: - redirect_stdio_to_logs() - + # Initialize and setup the homeserver hs = create_homeserver(homeserver_config) try: setup(hs) except Exception as e: handle_startup_exception(e) + # For problems immediately apparent during initialization, we want to log to + # stderr in the terminal so that they are obvious and visible to the operator. + # + # Now that we're past the initialization stage, we can redirect anything printed + # to stdio to the logs, if configured. + if not homeserver_config.logging.no_redirect_stdio: + redirect_stdio_to_logs() + # Register a callback to be invoked once the reactor is running register_start(hs, start, hs) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index fb937c63c..bd51aad9a 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -479,16 +479,21 @@ def main() -> None: # Create a logging context as soon as possible so we can start associating # everything with this homeserver. with LoggingContext(name="main", server_name=homeserver_config.server.server_name): - # redirect stdio to the logs, if configured. - if not homeserver_config.logging.no_redirect_stdio: - redirect_stdio_to_logs() - + # Initialize and setup the homeserver hs = create_homeserver(homeserver_config) try: setup(hs) except Exception as e: handle_startup_exception(e) + # For problems immediately apparent during initialization, we want to log to + # stderr in the terminal so that they are obvious and visible to the operator. + # + # Now that we're past the initialization stage, we can redirect anything printed + # to stdio to the logs, if configured. + if not homeserver_config.logging.no_redirect_stdio: + redirect_stdio_to_logs() + # Register a callback to be invoked once the reactor is running register_start(hs, start, hs)