2016-12-21 10:54:09 -08:00
|
|
|
from lbrynet.core import log_support
|
|
|
|
|
2016-03-14 12:30:22 -04:00
|
|
|
import argparse
|
2016-04-07 03:12:09 -04:00
|
|
|
import logging.handlers
|
2016-04-14 00:29:40 -04:00
|
|
|
|
2016-12-06 16:08:15 -05:00
|
|
|
from twisted.internet import defer, reactor
|
2016-03-14 12:30:22 -04:00
|
|
|
from jsonrpc.proxy import JSONRPCProxy
|
|
|
|
|
2016-11-10 15:49:51 -05:00
|
|
|
from lbrynet import analytics
|
2016-10-22 22:17:24 -07:00
|
|
|
from lbrynet import conf
|
2017-03-15 16:19:11 -04:00
|
|
|
from lbrynet.core import utils, system_info
|
2017-06-25 21:04:33 -04:00
|
|
|
from lbrynet.daemon.DaemonServer import DaemonServer
|
2016-10-19 00:12:44 -04:00
|
|
|
|
2016-06-07 04:19:51 -04:00
|
|
|
log = logging.getLogger(__name__)
|
2016-07-25 13:04:30 -05:00
|
|
|
|
2016-04-20 22:02:52 -04:00
|
|
|
|
2016-04-14 00:29:40 -04:00
|
|
|
def test_internet_connection():
|
2016-10-17 20:00:24 -05:00
|
|
|
return utils.check_connection()
|
2016-04-14 00:29:40 -04:00
|
|
|
|
2016-03-14 12:30:22 -04:00
|
|
|
|
|
|
|
def start():
|
2017-08-02 17:21:24 -04:00
|
|
|
"""The primary entry point for launching the daemon."""
|
2016-12-21 11:55:43 -08:00
|
|
|
conf.initialize_settings()
|
2017-01-16 22:23:20 -05:00
|
|
|
|
2016-03-14 12:30:22 -04:00
|
|
|
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
|
2017-03-15 16:19:11 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--wallet",
|
|
|
|
help="lbryum or ptc for testing, default lbryum",
|
|
|
|
type=str,
|
|
|
|
default=conf.settings['wallet']
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--http-auth", dest="useauth", action="store_true", default=conf.settings['use_auth_http']
|
|
|
|
)
|
2016-10-21 15:26:36 -07:00
|
|
|
parser.add_argument(
|
|
|
|
'--quiet', dest='quiet', action="store_true",
|
2017-03-15 16:19:11 -04:00
|
|
|
help='Disable all console output.'
|
|
|
|
)
|
2016-10-21 15:26:36 -07:00
|
|
|
parser.add_argument(
|
|
|
|
'--verbose', nargs="*",
|
|
|
|
help=('Enable debug output. Optionally specify loggers for which debug output '
|
2017-03-15 16:19:11 -04:00
|
|
|
'should selectively be applied.')
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--version', action="store_true",
|
|
|
|
help='Show daemon version and quit'
|
|
|
|
)
|
2016-04-17 23:23:20 -04:00
|
|
|
|
2017-01-16 22:23:20 -05:00
|
|
|
args = parser.parse_args()
|
2016-10-31 16:19:19 -05:00
|
|
|
update_settings_from_args(args)
|
|
|
|
|
2017-03-15 16:19:11 -04:00
|
|
|
if args.version:
|
|
|
|
version = system_info.get_platform(get_ip=False)
|
|
|
|
version['installation_id'] = conf.settings.installation_id
|
|
|
|
print utils.json_dumps_pretty(version)
|
|
|
|
return
|
|
|
|
|
2016-12-21 11:55:43 -08:00
|
|
|
lbrynet_log = conf.settings.get_log_filename()
|
2017-01-30 12:08:32 -08:00
|
|
|
log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
|
2017-01-16 22:23:20 -05:00
|
|
|
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
|
2016-10-19 00:12:44 -04:00
|
|
|
|
2016-03-29 16:42:47 -04:00
|
|
|
try:
|
2016-11-11 10:10:00 -06:00
|
|
|
log.debug('Checking for an existing lbrynet daemon instance')
|
2017-06-12 13:05:41 -04:00
|
|
|
JSONRPCProxy.from_url(conf.settings.get_api_connection_string()).status()
|
2016-03-29 16:42:47 -04:00
|
|
|
log.info("lbrynet-daemon is already running")
|
|
|
|
return
|
2016-11-11 10:10:00 -06:00
|
|
|
except Exception:
|
|
|
|
log.debug('No lbrynet instance found, continuing to start')
|
2016-03-29 16:42:47 -04:00
|
|
|
|
2016-03-14 12:30:22 -04:00
|
|
|
log.info("Starting lbrynet-daemon from command line")
|
|
|
|
|
2016-04-20 22:02:52 -04:00
|
|
|
if test_internet_connection():
|
2016-11-10 15:49:51 -05:00
|
|
|
analytics_manager = analytics.Manager.new_instance()
|
2017-06-21 18:17:54 -04:00
|
|
|
start_server_and_listen(args.useauth, analytics_manager)
|
2016-04-14 00:29:40 -04:00
|
|
|
reactor.run()
|
|
|
|
else:
|
|
|
|
log.info("Not connected to internet, unable to start")
|
2016-05-02 04:10:50 -04:00
|
|
|
|
2016-10-25 16:48:15 -05:00
|
|
|
|
2016-10-31 16:19:19 -05:00
|
|
|
def update_settings_from_args(args):
|
2017-08-02 15:50:17 -04:00
|
|
|
conf.settings.update({
|
|
|
|
'use_auth_http': args.useauth,
|
|
|
|
'wallet': args.wallet,
|
|
|
|
}, data_types=(conf.TYPE_CLI,))
|
2016-10-31 16:19:19 -05:00
|
|
|
|
|
|
|
|
2016-12-28 11:20:04 -06:00
|
|
|
@defer.inlineCallbacks
|
2017-08-02 15:50:17 -04:00
|
|
|
def start_server_and_listen(use_auth, analytics_manager):
|
|
|
|
"""
|
2016-10-25 18:36:40 -05:00
|
|
|
Args:
|
|
|
|
use_auth: set to true to enable http authentication
|
2016-11-10 15:49:51 -05:00
|
|
|
analytics_manager: to send analytics
|
2016-10-25 18:36:40 -05:00
|
|
|
"""
|
2016-12-21 12:59:52 -08:00
|
|
|
analytics_manager.send_server_startup()
|
2017-04-30 15:50:33 -04:00
|
|
|
daemon_server = DaemonServer(analytics_manager)
|
|
|
|
try:
|
2017-06-21 18:17:54 -04:00
|
|
|
yield daemon_server.start(use_auth)
|
2017-04-30 15:50:33 -04:00
|
|
|
analytics_manager.send_server_startup_success()
|
|
|
|
except Exception as e:
|
2017-09-01 10:32:47 -04:00
|
|
|
log.exception('Failed to start lbrynet-daemon')
|
2017-04-30 15:50:33 -04:00
|
|
|
analytics_manager.send_server_startup_error(str(e))
|
2017-08-02 17:21:24 -04:00
|
|
|
daemon_server.stop()
|
2016-10-25 18:36:40 -05:00
|
|
|
|
2016-11-02 07:23:37 -05:00
|
|
|
|
2016-05-02 04:10:50 -04:00
|
|
|
if __name__ == "__main__":
|
2016-07-16 01:15:58 -05:00
|
|
|
start()
|