lbry-sdk/lbrynet/daemon/DaemonControl.py

107 lines
3.1 KiB
Python
Raw Normal View History

2018-05-24 22:28:09 +02:00
import os
import sys
# Set SSL_CERT_FILE env variable for Twisted SSL verification on Windows
# This needs to happen before anything else
if 'win' in sys.platform:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
from lbrynet.core import log_support
import argparse
import logging.handlers
from twisted.internet import defer, reactor
#from jsonrpc.proxy import JSONRPCProxy
2016-10-23 07:17:24 +02:00
from lbrynet import conf
from lbrynet.core import utils, system_info
from lbrynet.daemon.Daemon import Daemon
2016-06-07 10:19:51 +02:00
log = logging.getLogger(__name__)
def test_internet_connection():
return utils.check_connection()
def start():
2017-08-02 23:21:24 +02:00
"""The primary entry point for launching the daemon."""
# postpone loading the config file to after the CLI arguments
# have been parsed, as they may contain an alternate config file location
conf.initialize_settings(load_conf_file=False)
2017-01-17 04:23:20 +01:00
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
parser.add_argument(
"--conf",
help="specify an alternative configuration file",
type=str,
default=None
)
parser.add_argument(
"--http-auth", dest="useauth", action="store_true", default=conf.settings['use_auth_http']
)
parser.add_argument(
'--quiet', dest='quiet', action="store_true",
help='Disable all console output.'
)
parser.add_argument(
'--verbose', nargs="*",
help=('Enable debug output. Optionally specify loggers for which debug output '
'should selectively be applied.')
)
parser.add_argument(
'--version', action="store_true",
help='Show daemon version and quit'
)
2017-01-17 04:23:20 +01:00
args = parser.parse_args()
update_settings_from_args(args)
conf.settings.load_conf_file_settings()
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
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)
log_support.configure_loggly_handler()
2017-01-17 04:23:20 +01:00
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
# fixme: fix that, JSONRPCProxy is gone on py3
#try:
# log.debug('Checking for an existing lbrynet daemon instance')
# JSONRPCProxy.from_url(conf.settings.get_api_connection_string()).status()
# log.info("lbrynet-daemon is already running")
# return
#except Exception:
# log.debug('No lbrynet instance found, continuing to start')
log.info("Starting lbrynet-daemon from command line")
if test_internet_connection():
daemon = Daemon()
daemon.start_listening()
reactor.run()
else:
log.info("Not connected to internet, unable to start")
2016-05-02 10:10:50 +02:00
def update_settings_from_args(args):
if args.conf:
conf.conf_file = args.conf
if args.useauth:
conf.settings.update({
'use_auth_http': args.useauth,
}, data_types=(conf.TYPE_CLI,))
2016-05-02 10:10:50 +02:00
if __name__ == "__main__":
start()