From 7a8879367414be332ad0946c2b37348d5f4fef9d Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Mon, 28 Jun 2021 12:14:55 +0200 Subject: Add a new signal handler for SIGQUIT. SIGQUIT signals the service to stop ALL sessions. How to send SIGQUIT via a terminal emulator: stty -a | grep intr --- rwa/support/sessionservice/service.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 3e9900d..6988beb 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -251,11 +251,16 @@ class RWASupportSessionService(dbus.service.Object): return False def _stop_all(self): - """Stop all sessions and this daemon.""" - logging.info("Stop all sessions and exit service.") + """Stop all sessions""" + logging.info("Stop all sessions.") for session in list(self.sessions.values()): session.stop() del self.sessions[session.pid] + + def _stop_daemon(self): + """Stop all sessions and this daemon.""" + logging.info("Shut down session service.") + self._stop_all() self.trigger_service.shutdown() self.loop.quit() @@ -317,11 +322,16 @@ def main(mockup, once): loop = GLib.MainLoop() service_object = RWASupportSessionService(loop, mockup, once) - def signal_handler(sig, frame): + def sigint_handler(sig, frame): logging.info("Service was terminated.") + service_object._stop_daemon() + + def sigquit_handler(sig, frame): + logging.info("Session was terminated.") service_object._stop_all() - signal.signal(signal.SIGINT, signal_handler) + signal.signal(signal.SIGINT, sigint_handler) + signal.signal(signal.SIGQUIT, sigquit_handler) loop.run() -- cgit v1.2.3 From 3712174c2d02b4a629e7ce0cbb7e8d3bd502d36b Mon Sep 17 00:00:00 2001 From: Jonathan Weth Date: Mon, 28 Jun 2021 12:56:12 +0200 Subject: Log connection errors in service better --- rwa/support/sessionservice/service.py | 2 +- rwa/support/sessionservice/session.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 3e9900d..a6e6aa1 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -121,7 +121,7 @@ class RWASupportSessionService(dbus.service.Object): return json.dumps(return_json) except ConnectionError: - pass + logging.error("There was a connection error while trying to reach the server.") return json.dumps({"status": "error", "type": "connection"}) diff --git a/rwa/support/sessionservice/session.py b/rwa/support/sessionservice/session.py index cabef5f..d3a6fd8 100644 --- a/rwa/support/sessionservice/session.py +++ b/rwa/support/sessionservice/session.py @@ -148,21 +148,21 @@ class Session: self.stop(triggered=True) raise ConnectionError() + if r.status_code != 200: + self.stop(triggered=True) + raise ConnectionError() + logging.info( "The session has been registered in RWA.Support.WebApp " f"with status code {r.status_code} and response {r.content.decode()}." ) - if r.status_code != 200: - self.stop(triggered=True) - raise ConnectionError() - self.meta = r.json() self.session_id = self.meta["session_id"] self.web_url = self.meta["url"] self.api_token = self.meta["token"] else: - logging.info("The session has pretended that he had created a session.") + logging.info("The service has pretended that he had created a session.") self.meta = {} self.session_id = int(random_digits(10)) self.web_url = f"http://example.com:{random_digits(5)}/app/rwasupport/test/" -- cgit v1.2.3