2018-05-24 21:28:09 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2018-05-24 17:12:47 -03: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-29 22:36:25 -04:00
|
|
|
import certifi
|
2018-05-24 17:12:47 -03:00
|
|
|
os.environ['SSL_CERT_FILE'] = certifi.where()
|
|
|
|
|
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
|
|
|
|
2018-07-25 01:23:02 -04:00
|
|
|
from twisted.internet import reactor
|
2016-03-14 12:30:22 -04:00
|
|
|
|
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
|
2018-07-20 16:46:15 -04:00
|
|
|
from lbrynet.daemon.Daemon import Daemon
|
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
|
|
|
|
2018-08-05 02:49:10 +05:30
|
|
|
def start(argv=None, conf_path=None):
|
|
|
|
if conf_path is not None:
|
|
|
|
conf.conf_file = conf_path
|
2017-12-29 19:55:30 +08:00
|
|
|
|
2018-08-05 02:49:10 +05:30
|
|
|
conf.initialize_settings()
|
2017-01-16 22:23:20 -05:00
|
|
|
|
2018-08-05 02:49:10 +05:30
|
|
|
parser = argparse.ArgumentParser()
|
2017-03-15 16:19:11 -04:00
|
|
|
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
|
|
|
|
2018-07-25 23:27:53 -04:00
|
|
|
args = parser.parse_args(argv)
|
2018-08-05 02:49:10 +05:30
|
|
|
if args.useauth:
|
|
|
|
conf.settings.update({'use_auth_http': args.useauth}, data_types=(conf.TYPE_CLI,))
|
2017-12-29 19:55:30 +08:00
|
|
|
|
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
|
2018-07-17 21:35:53 -03:00
|
|
|
print(utils.json_dumps_pretty(version))
|
2017-03-15 16:19:11 -04:00
|
|
|
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)
|
2018-07-20 16:46:15 -04:00
|
|
|
log_support.configure_loggly_handler()
|
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-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():
|
2018-07-20 16:46:15 -04:00
|
|
|
daemon = Daemon()
|
|
|
|
daemon.start_listening()
|
2016-04-14 00:29:40 -04:00
|
|
|
reactor.run()
|
|
|
|
else:
|
|
|
|
log.info("Not connected to internet, unable to start")
|