Skip to content
Snippets Groups Projects
Commit 666252f8 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Handle connection refused errors at start up

parent 6a5aad77
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,8 @@ import os ...@@ -18,6 +18,8 @@ import os
import sys import sys
import logging import logging
import argparse import argparse
import errno
import socket
from agkyra import protocol, protocol_client, gui, config from agkyra import protocol, protocol_client, gui, config
...@@ -229,13 +231,29 @@ class AgkyraCLI(cmd.Cmd): ...@@ -229,13 +231,29 @@ class AgkyraCLI(cmd.Cmd):
def client(self): def client(self):
"""Return the helper client instace or None""" """Return the helper client instace or None"""
self._client = getattr(self, '_client', None) self._client = getattr(self, '_client', None)
if not self._client: if self._client is None:
session = self.helper.load_active_session() self._client = self.try_make_client()
if session:
self._client = protocol_client.UIClient(session)
self._client.connect()
return self._client return self._client
def try_make_client(self):
session = self.helper.load_active_session()
if session:
client = protocol_client.UIClient(session)
try:
client.connect()
return client
except socket.error as e:
if e.errno == errno.ECONNREFUSED:
sys.stderr.write(
"It seems that a previous Agkyra execution hasn't "
"exited properly.\nPlease, try again after a few "
"seconds.\n")
exit(1)
else:
raise
else:
return None
def do_help(self, line): def do_help(self, line):
"""Help on agkyra GUI and CLI """Help on agkyra GUI and CLI
agkyra Run agkyra with GUI (equivalent to "agkyra gui") agkyra Run agkyra with GUI (equivalent to "agkyra gui")
...@@ -484,6 +502,17 @@ class AgkyraCLI(cmd.Cmd): ...@@ -484,6 +502,17 @@ class AgkyraCLI(cmd.Cmd):
sys.stderr.write('GUI interrupted by user, exiting\n') sys.stderr.write('GUI interrupted by user, exiting\n')
sys.stderr.flush() sys.stderr.flush()
new_gui.clean_exit() new_gui.clean_exit()
except socket.error as e:
if e.errno == errno.ECONNREFUSED:
sys.stderr.write(
"It seems that a previous Agkyra execution hasn't "
"exited properly.\nPlease, try again after a few "
"seconds.\n")
new_gui.clean_exit()
exit(1)
else:
raise
LOGGER.info('GUI is shutdown') LOGGER.info('GUI is shutdown')
if self.client: if self.client:
self._shutdown('') self._shutdown('')
......
...@@ -88,7 +88,11 @@ class GUI(WebSocketBaseClient): ...@@ -88,7 +88,11 @@ class GUI(WebSocketBaseClient):
LOG.debug('Removed session file %s' % self.session_file) LOG.debug('Removed session file %s' % self.session_file)
except Exception as e: except Exception as e:
LOG.warning('While cleaning GUI: %s' % e) LOG.warning('While cleaning GUI: %s' % e)
self.close() try:
self.close()
LOG.debug('Closed GUI connection')
except Exception as e:
LOG.warning('While cleaning GUI: %s' % e)
def handshake_ok(self): def handshake_ok(self):
"""If handshake OK is, SessionHelper UP goes, so GUI launched can be""" """If handshake OK is, SessionHelper UP goes, so GUI launched can be"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment