# HG changeset patch # User Goffi # Date 1605891763 -3600 # Node ID ce5cfe004d4e10ada9cf516a93466d254771b5e3 # Parent f61e95438050171863f622ba54a2a44a9cca3627 server: new `--bridge-retries` option: If bridge connection fails, it will be retried for the specified number of time (default to 10) before giving up. Each try is spaced by 1 second. diff -r f61e95438050 -r ce5cfe004d4e libervia/server/server.py --- a/libervia/server/server.py Fri Nov 20 17:55:21 2020 +0100 +++ b/libervia/server/server.py Fri Nov 20 18:02:43 2020 +0100 @@ -834,6 +834,7 @@ self.ns_map = {} # map of short name to namespaces ## bridge ## + self._bridge_retry = self.options['bridge-retries'] self.bridge = Bridge() self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) @@ -1207,6 +1208,7 @@ self.site.sessionFactory = LiberviaSession def _bridgeCb(self): + del self._bridge_retry self.bridge.getReady( lambda: self.initialised.callback(None), lambda failure: self.initialised.errback(Exception(failure)), @@ -1215,6 +1217,22 @@ def _bridgeEb(self, failure_): if isinstance(failure_, BridgeExceptionNoService): + if self._bridge_retry: + if self._bridge_retry < 0: + print(_("Can't connect to bridge, will retry indefinitely. " + "Next try in 1s.")) + else: + self._bridge_retry -= 1 + print( + _( + "Can't connect to bridge, will retry in 1 s ({retries_left} " + "trie(s) left)." + ).format(retries_left=self._bridge_retry) + ) + time.sleep(1) + self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) + return + print("Can't connect to SàT backend, are you sure it's launched ?") else: log.error("Can't connect to bridge: {}".format(failure)) diff -r f61e95438050 -r ce5cfe004d4e twisted/plugins/libervia_server.py --- a/twisted/plugins/libervia_server.py Fri Nov 20 17:55:21 2020 +0100 +++ b/twisted/plugins/libervia_server.py Fri Nov 20 18:02:43 2020 +0100 @@ -131,6 +131,8 @@ ['base_url_ext', '', '', _('The external URL to use as base URL'), coerceUnicode], + ['bridge-retries', '', 10, + _('Number of tries to connect to bridge before giving up'), int], ] # Options which are in sat.conf only