forked from LBRYCommunity/lbry-sdk
Merge pull request #554 from lbryio/fix_restart
Fix restart procedure in DaemonControl
This commit is contained in:
commit
c18c1725c4
3 changed files with 13 additions and 4 deletions
|
@ -19,7 +19,7 @@ at anytime.
|
||||||
*
|
*
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
*
|
* Fix restart procedure in DaemonControl
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
|
@ -131,9 +131,11 @@ def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5):
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception('Failed to startup')
|
log.exception('Failed to startup')
|
||||||
|
yield daemon_server.stop()
|
||||||
analytics_manager.send_server_startup_error(str(e))
|
analytics_manager.send_server_startup_error(str(e))
|
||||||
tries += 1
|
tries += 1
|
||||||
else:
|
else:
|
||||||
|
log.warn("Exceeded max tries to start up, stopping")
|
||||||
reactor.callFromThread(reactor.stop)
|
reactor.callFromThread(reactor.stop)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from twisted.web import server, guard
|
from twisted.web import server, guard
|
||||||
from twisted.internet import defer, reactor, error
|
from twisted.internet import defer, reactor, error
|
||||||
|
@ -19,7 +18,9 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DaemonServer(object):
|
class DaemonServer(object):
|
||||||
def __init__(self, analytics_manager=None):
|
def __init__(self, analytics_manager=None):
|
||||||
|
self._api = None
|
||||||
self.root = None
|
self.root = None
|
||||||
|
self.server_port = None
|
||||||
self.analytics_manager = analytics_manager
|
self.analytics_manager = analytics_manager
|
||||||
|
|
||||||
def _setup_server(self, use_auth):
|
def _setup_server(self, use_auth):
|
||||||
|
@ -34,11 +35,11 @@ class DaemonServer(object):
|
||||||
lbrynet_server.requestFactory = DaemonRequest
|
lbrynet_server.requestFactory = DaemonRequest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reactor.listenTCP(
|
self.server_port = reactor.listenTCP(
|
||||||
conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
|
conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
|
||||||
except error.CannotListenError:
|
except error.CannotListenError:
|
||||||
log.info('Daemon already running, exiting app')
|
log.info('Daemon already running, exiting app')
|
||||||
sys.exit(1)
|
raise
|
||||||
|
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
|
@ -47,6 +48,12 @@ class DaemonServer(object):
|
||||||
yield self._setup_server(use_auth)
|
yield self._setup_server(use_auth)
|
||||||
yield self._api.setup(launch_ui)
|
yield self._api.setup(launch_ui)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def stop(self):
|
||||||
|
if self._api is not None:
|
||||||
|
yield self._api._shutdown()
|
||||||
|
if self.server_port is not None:
|
||||||
|
yield self.server_port.stopListening()
|
||||||
|
|
||||||
def get_site_base(use_auth, root):
|
def get_site_base(use_auth, root):
|
||||||
if use_auth:
|
if use_auth:
|
||||||
|
|
Loading…
Reference in a new issue