forked from LBRYCommunity/lbry-sdk
shutdown if there are errors during setup
This commit is contained in:
parent
b360eb6181
commit
5d45345398
3 changed files with 32 additions and 6 deletions
|
@ -139,3 +139,17 @@ class JsonFormatter(logging.Formatter):
|
||||||
if record.exc_info:
|
if record.exc_info:
|
||||||
data['exc_info'] = self.formatException(record.exc_info)
|
data['exc_info'] = self.formatException(record.exc_info)
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
|
def failure(failure, log, msg, *args):
|
||||||
|
"""Log a failure message from a deferred.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
failure: twisted.python.failure.Failure
|
||||||
|
log: a python logger instance
|
||||||
|
msg: the message to log. Can use normal logging string interpolation.
|
||||||
|
the last argument will be set to the error message from the failure.
|
||||||
|
args: values to substitute into `msg`
|
||||||
|
"""
|
||||||
|
args += (failure.getErrorMessage(),)
|
||||||
|
log.error(msg, *args, exc_info=failure.getTracebackObject())
|
||||||
|
|
|
@ -262,6 +262,8 @@ class Daemon(jsonrpc.JSONRPC):
|
||||||
self.first_run_after_update = False
|
self.first_run_after_update = False
|
||||||
self.uploaded_temp_files = []
|
self.uploaded_temp_files = []
|
||||||
self._session_id = base58.b58encode(generate_id())
|
self._session_id = base58.b58encode(generate_id())
|
||||||
|
self.analytics_manager = None
|
||||||
|
self.lbryid = None
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||||
|
@ -636,11 +638,8 @@ class Daemon(jsonrpc.JSONRPC):
|
||||||
d.addCallback(lambda _: self._setup_server())
|
d.addCallback(lambda _: self._setup_server())
|
||||||
d.addCallback(lambda _: _log_starting_vals())
|
d.addCallback(lambda _: _log_starting_vals())
|
||||||
d.addCallback(lambda _: _announce_startup())
|
d.addCallback(lambda _: _announce_startup())
|
||||||
# TODO: handle errors here
|
|
||||||
d.callback(None)
|
d.callback(None)
|
||||||
|
return d
|
||||||
return defer.succeed(None)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_platform(self):
|
def _get_platform(self):
|
||||||
r = {
|
r = {
|
||||||
|
@ -870,13 +869,19 @@ class Daemon(jsonrpc.JSONRPC):
|
||||||
log.info("Closing lbrynet session")
|
log.info("Closing lbrynet session")
|
||||||
log.info("Status at time of shutdown: " + self.startup_status[0])
|
log.info("Status at time of shutdown: " + self.startup_status[0])
|
||||||
self.looping_call_manager.shutdown()
|
self.looping_call_manager.shutdown()
|
||||||
self.analytics_manager.shutdown()
|
if self.analytics_manager:
|
||||||
|
self.analytics_manager.shutdown()
|
||||||
if self.lbry_ui_manager.update_checker.running:
|
if self.lbry_ui_manager.update_checker.running:
|
||||||
self.lbry_ui_manager.update_checker.stop()
|
self.lbry_ui_manager.update_checker.stop()
|
||||||
|
|
||||||
self._clean_up_temp_files()
|
self._clean_up_temp_files()
|
||||||
|
|
||||||
d = self._upload_log(log_type="close", exclude_previous=False if self.first_run else True)
|
try:
|
||||||
|
d = self._upload_log(
|
||||||
|
log_type="close", exclude_previous=False if self.first_run else True)
|
||||||
|
except Exception:
|
||||||
|
log.warn('Failed to upload log', exc_info=True)
|
||||||
|
d = defer.succeed(None)
|
||||||
d.addCallback(lambda _: self._stop_server())
|
d.addCallback(lambda _: self._stop_server())
|
||||||
d.addCallback(lambda _: self._stop_reflector())
|
d.addCallback(lambda _: self._stop_reflector())
|
||||||
d.addErrback(lambda err: True)
|
d.addErrback(lambda err: True)
|
||||||
|
|
|
@ -109,6 +109,7 @@ def start():
|
||||||
branch_specified=True if args.branch else False)
|
branch_specified=True if args.branch else False)
|
||||||
if args.launchui:
|
if args.launchui:
|
||||||
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||||
|
d.addErrback(log_and_kill)
|
||||||
|
|
||||||
lbrynet_server = server.Site(lbry.root)
|
lbrynet_server = server.Site(lbry.root)
|
||||||
lbrynet_server.requestFactory = DaemonRequest
|
lbrynet_server.requestFactory = DaemonRequest
|
||||||
|
@ -123,5 +124,11 @@ def start():
|
||||||
print "Not connected to internet, unable to start"
|
print "Not connected to internet, unable to start"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def log_and_kill(failure):
|
||||||
|
log_support.failure(failure, log, 'Failed to startup: %s')
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
start()
|
start()
|
||||||
|
|
Loading…
Reference in a new issue