Fix restart procedure in DaemonControl

This commit is contained in:
Kay Kurokawa 2017-03-22 11:16:13 -04:00
parent 790baea191
commit 5e6a742bd3
3 changed files with 13 additions and 4 deletions

View file

@ -19,7 +19,7 @@ at anytime.
*
### Fixed
*
* Fix restart procedure in DaemonControl
*
*

View file

@ -131,9 +131,11 @@ def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5):
break
except Exception as e:
log.exception('Failed to startup')
yield daemon_server.stop()
analytics_manager.send_server_startup_error(str(e))
tries += 1
else:
log.warn("Exceeded max tries to start up, stopping")
reactor.callFromThread(reactor.stop)

View file

@ -1,6 +1,5 @@
import logging
import os
import sys
from twisted.web import server, guard
from twisted.internet import defer, reactor, error
@ -19,7 +18,9 @@ log = logging.getLogger(__name__)
class DaemonServer(object):
def __init__(self, analytics_manager=None):
self._api = None
self.root = None
self.server_port = None
self.analytics_manager = analytics_manager
def _setup_server(self, use_auth):
@ -34,11 +35,11 @@ class DaemonServer(object):
lbrynet_server.requestFactory = DaemonRequest
try:
reactor.listenTCP(
self.server_port = reactor.listenTCP(
conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
except error.CannotListenError:
log.info('Daemon already running, exiting app')
sys.exit(1)
raise
return defer.succeed(True)
@ -47,6 +48,12 @@ class DaemonServer(object):
yield self._setup_server(use_auth)
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):
if use_auth: