2018-05-24 22:28:09 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2018-05-24 22:12:47 +02:00
|
|
|
# Set SSL_CERT_FILE env variable for Twisted SSL verification on Windows
|
|
|
|
# This needs to happen before anything else
|
|
|
|
if 'win' in sys.platform:
|
2018-05-30 04:36:25 +02:00
|
|
|
import certifi
|
2018-05-24 22:12:47 +02:00
|
|
|
os.environ['SSL_CERT_FILE'] = certifi.where()
|
|
|
|
|
2016-12-21 19:54:09 +01:00
|
|
|
from lbrynet.core import log_support
|
|
|
|
|
2016-03-14 17:30:22 +01:00
|
|
|
import argparse
|
2016-04-07 09:12:09 +02:00
|
|
|
import logging.handlers
|
2016-04-14 06:29:40 +02:00
|
|
|
|
2018-07-25 07:23:02 +02:00
|
|
|
from twisted.internet import reactor
|
2016-03-14 17:30:22 +01:00
|
|
|
|
2016-10-23 07:17:24 +02:00
|
|
|
from lbrynet import conf
|
2017-03-15 21:19:11 +01:00
|
|
|
from lbrynet.core import utils, system_info
|
2018-07-20 22:46:15 +02:00
|
|
|
from lbrynet.daemon.Daemon import Daemon
|
2016-10-19 06:12:44 +02:00
|
|
|
|
2016-06-07 10:19:51 +02:00
|
|
|
log = logging.getLogger(__name__)
|
2016-07-25 20:04:30 +02:00
|
|
|
|
2016-04-21 04:02:52 +02:00
|
|
|
|
2016-04-14 06:29:40 +02:00
|
|
|
def test_internet_connection():
|
2016-10-18 03:00:24 +02:00
|
|
|
return utils.check_connection()
|
2016-04-14 06:29:40 +02:00
|
|
|
|
2016-03-14 17:30:22 +01:00
|
|
|
|
2018-08-04 23:19:10 +02:00
|
|
|
def start(argv=None, conf_path=None):
|
|
|
|
if conf_path is not None:
|
|
|
|
conf.conf_file = conf_path
|
2017-12-29 12:55:30 +01:00
|
|
|
|
2018-08-04 23:19:10 +02:00
|
|
|
conf.initialize_settings()
|
2017-01-17 04:23:20 +01:00
|
|
|
|
2018-08-04 23:19:10 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
2017-03-15 21:19:11 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--http-auth", dest="useauth", action="store_true", default=conf.settings['use_auth_http']
|
|
|
|
)
|
2016-10-22 00:26:36 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'--quiet', dest='quiet', action="store_true",
|
2017-03-15 21:19:11 +01:00
|
|
|
help='Disable all console output.'
|
|
|
|
)
|
2016-10-22 00:26:36 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'--verbose', nargs="*",
|
|
|
|
help=('Enable debug output. Optionally specify loggers for which debug output '
|
2017-03-15 21:19:11 +01:00
|
|
|
'should selectively be applied.')
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--version', action="store_true",
|
|
|
|
help='Show daemon version and quit'
|
|
|
|
)
|
2016-04-18 05:23:20 +02:00
|
|
|
|
2018-07-26 05:27:53 +02:00
|
|
|
args = parser.parse_args(argv)
|
2018-08-04 23:19:10 +02:00
|
|
|
if args.useauth:
|
|
|
|
conf.settings.update({'use_auth_http': args.useauth}, data_types=(conf.TYPE_CLI,))
|
2017-12-29 12:55:30 +01:00
|
|
|
|
2017-03-15 21:19:11 +01:00
|
|
|
if args.version:
|
|
|
|
version = system_info.get_platform(get_ip=False)
|
|
|
|
version['installation_id'] = conf.settings.installation_id
|
2018-07-18 02:35:53 +02:00
|
|
|
print(utils.json_dumps_pretty(version))
|
2017-03-15 21:19:11 +01:00
|
|
|
return
|
|
|
|
|
2016-12-21 20:55:43 +01:00
|
|
|
lbrynet_log = conf.settings.get_log_filename()
|
2017-01-30 21:08:32 +01:00
|
|
|
log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
|
2018-07-20 22:46:15 +02:00
|
|
|
log_support.configure_loggly_handler()
|
2017-01-17 04:23:20 +01:00
|
|
|
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
|
2016-10-19 06:12:44 +02:00
|
|
|
|
2016-03-14 17:30:22 +01:00
|
|
|
log.info("Starting lbrynet-daemon from command line")
|
|
|
|
|
2016-04-21 04:02:52 +02:00
|
|
|
if test_internet_connection():
|
2018-07-20 22:46:15 +02:00
|
|
|
daemon = Daemon()
|
|
|
|
daemon.start_listening()
|
2016-04-14 06:29:40 +02:00
|
|
|
reactor.run()
|
|
|
|
else:
|
|
|
|
log.info("Not connected to internet, unable to start")
|