separate try/except for media server

This commit is contained in:
Alex Grintsvayg 2019-06-18 08:53:59 -04:00 committed by Lex Berezhny
parent f78323e0fb
commit a60cd1d475

View file

@ -414,20 +414,24 @@ class Daemon(metaclass=JSONRPCServerType):
try: try:
rpc_site = web.TCPSite(self.rpc_runner, self.conf.api_host, self.conf.api_port, shutdown_timeout=.5) rpc_site = web.TCPSite(self.rpc_runner, self.conf.api_host, self.conf.api_port, shutdown_timeout=.5)
await rpc_site.start() await rpc_site.start()
log.info('lbrynet API listening on TCP %s:%i', *rpc_site._server.sockets[0].getsockname()[:2]) log.info('RPC server listening on TCP %s:%i', *rpc_site._server.sockets[0].getsockname()[:2])
except OSError as e:
log.error('RPC server failed to bind TCP %s:%i', self.conf.api_host, self.conf.api_port)
await self.analytics_manager.send_server_startup_error(str(e))
raise SystemExit()
try:
streaming_site = web.TCPSite(self.streaming_runner, self.conf.streaming_host, self.conf.streaming_port, streaming_site = web.TCPSite(self.streaming_runner, self.conf.streaming_host, self.conf.streaming_port,
shutdown_timeout=.5) shutdown_timeout=.5)
await streaming_site.start() await streaming_site.start()
log.info('lbrynet media server listening on TCP %s:%i', log.info('media server listening on TCP %s:%i', *streaming_site._server.sockets[0].getsockname()[:2])
*streaming_site._server.sockets[0].getsockname()[:2])
except OSError as e: except OSError as e:
log.error('lbrynet API failed to bind TCP %s for listening. Daemon is already running or this port is ' log.error('media server failed to bind TCP %s:%i', self.conf.streaming_host, self.conf.streaming_port)
'already in use by another application.', self.conf.api)
await self.analytics_manager.send_server_startup_error(str(e)) await self.analytics_manager.send_server_startup_error(str(e))
raise SystemExit() raise SystemExit()
try: try:
await self.initialize() await self.initialize()
except asyncio.CancelledError: except asyncio.CancelledError:
@ -436,7 +440,7 @@ class Daemon(metaclass=JSONRPCServerType):
await self.stop() await self.stop()
except Exception as e: except Exception as e:
await self.analytics_manager.send_server_startup_error(str(e)) await self.analytics_manager.send_server_startup_error(str(e))
log.exception('Failed to start lbrynet-daemon') log.exception('Failed to start lbrynet')
await self.analytics_manager.send_server_startup_success() await self.analytics_manager.send_server_startup_success()