1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-05 09:17:54 +03:00

fixes for service

This commit is contained in:
Adolfo Gómez García 2020-01-20 17:18:48 +01:00
parent 7cc6c6d3b8
commit 45429027bf

View File

@ -59,6 +59,7 @@ class CommonService: # pylint: disable=too-many-instance-attributes
_isAlive: bool = True
_rebootRequested: bool = False
_loggedIn = False
_ready = False
_cfg: types.ActorConfigurationType
_api: rest.UDSServerApi
@ -127,6 +128,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes
if not self._isAlive:
return
self._ready = False
# First, if postconfig is available, execute it and disable it
if self._cfg.post_command:
self.execute(self._cfg.post_command, 'postConfig')
@ -143,7 +146,9 @@ class CommonService: # pylint: disable=too-many-instance-attributes
counter -= 1
try:
self._certificate = self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip, rest.LISTEN_PORT)
self._ready = True
except rest.RESTConnectionError as e:
logger.error('Error en ready: %s', e)
if not logged: # Only log connection problems ONCE
logged = True
logger.error('Error connecting with UDS Broker')
@ -272,7 +277,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes
if self._loggedIn and self._cfg.own_token:
self._loggedIn = False
try:
self._api.logout(self._cfg.own_token, '')
if self._ready:
self._api.logout(self._cfg.own_token, '')
except Exception as e:
logger.error('Error notifying final logout to UDS: %s', e)
@ -358,6 +364,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes
# Client notifications
def login(self, username: str) -> types.LoginResultInfoType:
if not self._ready:
return types.LoginResultInfoType('', '', 0, 0)
result = types.LoginResultInfoType(ip='', hostname='', dead_line=None, max_idle=None)
self._loggedIn = True
if self._cfg.own_token:
@ -365,6 +373,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes
return result
def logout(self, username: str) -> None:
if not self._ready:
return
self._loggedIn = False
if self._cfg.own_token:
self._api.logout(self._cfg.own_token, username)