def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p]) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument("--store", help="specify a store address [default: %(default)s]", default=STORE_ADDR) p.add_argument('--p2p', action='store_true', help='enable experimental p2p support') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) with Router(listen=args.listen, hunter=args.hunter, store=args.store, p2p=args.p2p) as r: try: logger.info('starting router..') r.run() except KeyboardInterrupt: logger.info('shutting down...') logger.info('Shutting down')
def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ example usage: $ cif-httpd -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-httpd', parents=[p]) router_address = app.config.get('CIF_ROUTER_ADDR', ROUTER_ADDR) p.add_argument("--router", help="specify router frontend [default %(default)s]", default=router_address) p.add_argument('--token', help="specify cif-httpd token [default %(default)s]", default=TOKEN) p.add_argument( '--listen', help='specify the interface to listen on [default %(default)s]', default=HTTP_LISTEN) p.add_argument('--listen-port', help='specify the port to listen on [default %(default)s]', default=HTTP_LISTEN_PORT) p.add_argument('--fdebug', action='store_true') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) try: logger.info('pinging router...') app.config["SECRET_KEY"] = os.urandom(1024) logger.info('starting up...') app.run(host=args.listen, port=args.listen_port, debug=args.fdebug, threaded=True) except KeyboardInterrupt: logger.info('shutting down...') raise SystemExit
def main(): p = get_argument_parser() p = ArgumentParser( description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p] ) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument("--store", help="specify a store address [default: %(default)s]", default=STORE_ADDR) p.add_argument('--p2p', action='store_true', help='enable experimental p2p support') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format(logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) with Router(listen=args.listen, hunter=args.hunter, store=args.store, p2p=args.p2p) as r: try: logger.info('starting router..') r.run() except KeyboardInterrupt: logger.info('shutting down...') logger.info('Shutting down')
def main(): p = get_argument_parser() p = ArgumentParser( description=textwrap.dedent('''\ example usage: $ cif-httpd -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-httpd', parents=[p] ) router_address = app.config.get('CIF_ROUTER_ADDR', ROUTER_ADDR) p.add_argument("--router", help="specify router frontend [default %(default)s]", default=router_address) p.add_argument('--token', help="specify cif-httpd token [default %(default)s]", default=TOKEN) p.add_argument('--listen', help='specify the interface to listen on [default %(default)s]', default=HTTP_LISTEN) p.add_argument('--listen-port', help='specify the port to listen on [default %(default)s]', default=HTTP_LISTEN_PORT) p.add_argument('--fdebug', action='store_true') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format(logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) try: logger.info('pinging router...') app.config["SECRET_KEY"] = os.urandom(1024) logger.info('starting up...') app.run(host=args.listen, port=args.listen_port, debug=args.fdebug, threaded=True) except KeyboardInterrupt: logger.info('shutting down...') raise SystemExit
def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ example usage: $ cif-httpd -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-httpd', parents=[p]) p.add_argument('--fdebug', action='store_true') args = p.parse_args() setup_logging(args) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) setup_runtime_path(args.runtime_path) if not args.fdebug: # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) try: logger.info('pinging router...') logger.info('starting up...') app.run(host=HTTP_LISTEN, port=HTTP_LISTEN_PORT, debug=args.fdebug) except KeyboardInterrupt: logger.info('shutting down...') except Exception as e: logger.critical(e) traceback.print_exc()
def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_CONFIG_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_HUNTER_TOKEN CIF_HUNTER_THREADS CIF_GATHERER_THREADS CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p]) p.add_argument('--config', help='specify config path [default: %(default)s', default=CONFIG_PATH) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument( '--gatherer-threads', help='specify number of gatherer threads to use [default: %(default)s]', default=GATHERER_THREADS) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument( '--hunter-token', help='specify token for hunters to use [default: %(default)s]', default=HUNTER_TOKEN) p.add_argument( '--hunter-threads', help='specify number of hunter threads to use [default: %(default)s]', default=HUNTER_THREADS) p.add_argument( "--store-address", help="specify the store address cif-router is listening on[default: %(" "default)s]", default=STORE_ADDR) p.add_argument( "--store", help="specify a store type {} [default: %(default)s]".format( ', '.join(STORE_PLUGINS)), default=STORE_DEFAULT) p.add_argument('--store-nodes', help='specify storage nodes address [default: %(default)s]', default=STORE_NODES) p.add_argument('--p2p', action='store_true', help='enable experimental p2p support') p.add_argument('--logging-ignore', help='set logging to WARNING for specific modules') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) if args.logging_ignore: to_ignore = args.logging_ignore.split(',') for i in to_ignore: logging.getLogger(i).setLevel(logging.WARNING) o = read_config(args) options = vars(args) for v in options: if options[v] is None: options[v] = o.get(v) setup_signals(__name__) setup_runtime_path(args.runtime_path) with Router(listen=args.listen, hunter=args.hunter, store_type=args.store, store_address=args.store_address, store_nodes=args.store_nodes, p2p=args.p2p, hunter_token=args.hunter_token, hunter_threads=args.hunter_threads, gatherer_threads=args.gatherer_threads) as r: try: logger.info('starting router..') r.start() except KeyboardInterrupt: # todo - signal to threads to shut down and wait for them to finish logger.info('shutting down...') logger.info('Shutting down')
def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ example usage: $ cif-httpd -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-httpd', parents=[p]) router_address = app.config.get('CIF_ROUTER_ADDR', ROUTER_ADDR) p.add_argument("--router", help="specify router frontend [default %(default)s]", default=router_address) p.add_argument( '--listen', help='specify the interface to listen on [default %(default)s]', default=HTTP_LISTEN) p.add_argument('--listen-port', help='specify the port to listen on [default %(default)s]', default=HTTP_LISTEN_PORT) p.add_argument('--pidfile', help='specify pidfile location [default: %(default)s]', default=PIDFILE) p.add_argument('--fdebug', action='store_true') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) if TRACE: logger.setLevel(logging.DEBUG) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) if not args.fdebug: # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) if os.path.isfile(args.pidfile): logger.critical("%s already exists, exiting" % args.pidfile) raise SystemExit try: pidfile = open(args.pidfile, 'w') pidfile.write(pid) pidfile.close() except PermissionError as e: logger.error('unable to create pid %s' % args.pidfile) try: logger.info('pinging router...') logger.info('starting up...') app.run(host=args.listen, port=args.listen_port, debug=args.fdebug, threaded=True, extra_files=extra_files) except KeyboardInterrupt: logger.info('shutting down...') except Exception as e: logger.critical(e) traceback.print_exc() if os.path.isfile(args.pidfile): os.unlink(args.pidfile)
def main(): p = get_argument_parser() p = ArgumentParser(description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_CONFIG_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_HUNTER_TOKEN CIF_HUNTER_THREADS CIF_GATHERER_THREADS CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p]) p.add_argument('--config', help='specify config path [default: %(default)s', default=CONFIG_PATH) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument( '--gatherer-threads', help='specify number of gatherer threads to use [default: %(default)s]', default=GATHERER_THREADS) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument( '--hunter-token', help='specify token for hunters to use [default: %(default)s]', default=HUNTER_TOKEN) p.add_argument( '--hunter-threads', help='specify number of hunter threads to use [default: %(default)s]', default=HUNTER_THREADS) p.add_argument( "--store-address", help="specify the store address cif-router is listening on[default: %(" "default)s]", default=STORE_ADDR) p.add_argument( "--store", help="specify a store type {} [default: %(default)s]".format( ', '.join(STORE_PLUGINS)), default=STORE_DEFAULT) p.add_argument('--store-nodes', help='specify storage nodes address [default: %(default)s]', default=STORE_NODES) p.add_argument('--logging-ignore', help='set logging to WARNING for specific modules') p.add_argument('--pidfile', help='specify pidfile location [default: %(default)s]', default=PIDFILE) args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format( logging.getLevelName(logger.getEffectiveLevel()))) if args.logging_ignore: to_ignore = args.logging_ignore.split(',') for i in to_ignore: logging.getLogger(i).setLevel(logging.WARNING) o = read_config(args) options = vars(args) for v in options: if options[v] is None: options[v] = o.get(v) setup_runtime_path(args.runtime_path) setup_signals(__name__) # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) if os.path.isfile(args.pidfile): logger.critical("%s already exists, exiting" % args.pidfile) raise SystemExit try: pidfile = open(args.pidfile, 'w') pidfile.write(pid) pidfile.close() except PermissionError as e: logger.error('unable to create pid %s' % args.pidfile) with Router(listen=args.listen, hunter=args.hunter, store_type=args.store, store_address=args.store_address, store_nodes=args.store_nodes, hunter_token=args.hunter_token, hunter_threads=args.hunter_threads, gatherer_threads=args.gatherer_threads) as r: try: logger.info('starting router..') r.start() except KeyboardInterrupt: # todo - signal to threads to shut down and wait for them to finish logger.info('shutting down via SIGINT...') except SystemExit: logger.info('shutting down via SystemExit...') except Exception as e: logger.critical(e) traceback.print_exc() r.stop() logger.info('Shutting down') if os.path.isfile(args.pidfile): os.unlink(args.pidfile)
def main(): p = ArgumentParser( description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_ADDR example usage: $ CIF_ROUTER_ADDR=0.0.0.0 cif-router -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', ) p.add_argument("--runtime-path", help="specify the runtime path [default %(default)s]", default=RUNTIME_PATH) p.add_argument('-d', '--debug', dest='debug', action="store_true") p.add_argument('-v', '--verbose', action='store_true') p.add_argument('-V', '--version', action='version', version=VERSION) p.add_argument('-E', '--enrichment', help='Enable Enrichment', default=ENRICHMENT, action='store_true') p.add_argument('-H', '--hunt', help='Enable Hunting', action='store_true', default=HUNT) p.add_argument("--store", help=f"specify a store type {', '.join(STORE_PLUGINS)} " f"[default: %(default)s]", default=STORE_DEFAULT) p.add_argument('--logging-ignore', help='set logging to WARNING for specific modules') args = p.parse_args() setup_logging(args) if args.verbose: logger.setLevel(logging.INFO) if args.debug: logger.setLevel(logging.DEBUG) logger.info(f"loglevel: {logger.getEffectiveLevel()}") if args.logging_ignore: to_ignore = args.logging_ignore.split(',') for i in to_ignore: logging.getLogger(i).setLevel(logging.WARNING) setup_runtime_path(args.runtime_path) # setup_signals(__name__) # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) r = Router(store_type=args.store, enrichment=args.enrichment, hunt=args.hunt) try: logger.info('starting router..') r.start() except KeyboardInterrupt: # todo - signal to threads to shut down and wait for them to finish logger.info('shutting down via SIGINT...') except SystemExit: logger.info('shutting down via SystemExit...') except Exception as e: logger.critical(e) traceback.print_exc() logger.info('stopping..') r.stop() logger.info('Shutting down')
def main(): p = get_argument_parser() p = ArgumentParser( description=textwrap.dedent('''\ example usage: $ cif-httpd -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-httpd', parents=[p] ) router_address = app.config.get('CIF_ROUTER_ADDR', ROUTER_ADDR) p.add_argument("--router", help="specify router frontend [default %(default)s]", default=router_address) p.add_argument('--listen', help='specify the interface to listen on [default %(default)s]', default=HTTP_LISTEN) p.add_argument('--listen-port', help='specify the port to listen on [default %(default)s]', default=HTTP_LISTEN_PORT) p.add_argument('--pidfile', help='specify pidfile location [default: %(default)s]', default=PIDFILE) p.add_argument('--fdebug', action='store_true') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) if TRACE: logger.setLevel(logging.DEBUG) logger.info('loglevel is: {}'.format(logging.getLevelName(logger.getEffectiveLevel()))) setup_signals(__name__) setup_runtime_path(args.runtime_path) if not args.fdebug: # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) if os.path.isfile(args.pidfile): logger.critical("%s already exists, exiting" % args.pidfile) raise SystemExit try: pidfile = open(args.pidfile, 'w') pidfile.write(pid) pidfile.close() except PermissionError as e: logger.error('unable to create pid %s' % args.pidfile) try: logger.info('pinging router...') logger.info('starting up...') app.run(host=args.listen, port=args.listen_port, debug=args.fdebug, threaded=True, extra_files=extra_files) except KeyboardInterrupt: logger.info('shutting down...') except Exception as e: logger.critical(e) traceback.print_exc() if os.path.isfile(args.pidfile): os.unlink(args.pidfile)
def main(): p = get_argument_parser() p = ArgumentParser( description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_CONFIG_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_HUNTER_TOKEN CIF_HUNTER_THREADS CIF_GATHERER_THREADS CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p] ) p.add_argument('--config', help='specify config path [default: %(default)s', default=CONFIG_PATH) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument('--gatherer-threads', help='specify number of gatherer threads to use [default: %(default)s]', default=GATHERER_THREADS) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument('--hunter-token', help='specify token for hunters to use [default: %(default)s]', default=HUNTER_TOKEN) p.add_argument('--hunter-threads', help='specify number of hunter threads to use [default: %(default)s]', default=HUNTER_THREADS) p.add_argument("--store-address", help="specify the store address cif-router is listening on[default: %(" "default)s]", default=STORE_ADDR) p.add_argument("--store", help="specify a store type {} [default: %(default)s]".format(', '.join(STORE_PLUGINS)), default=STORE_DEFAULT) p.add_argument('--store-nodes', help='specify storage nodes address [default: %(default)s]', default=STORE_NODES) p.add_argument('--p2p', action='store_true', help='enable experimental p2p support') args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format(logging.getLevelName(logger.getEffectiveLevel()))) o = read_config(args) options = vars(args) for v in options: if options[v] is None: options[v] = o.get(v) setup_signals(__name__) setup_runtime_path(args.runtime_path) with Router(listen=args.listen, hunter=args.hunter, store_type=args.store, store_address=args.store_address, store_nodes=args.store_nodes, p2p=args.p2p, hunter_token=args.hunter_token, hunter_threads=args.hunter_threads, gatherer_threads=args.gatherer_threads) as r: try: logger.info('starting router..') r.start() except KeyboardInterrupt: # todo - signal to threads to shut down and wait for them to finish logger.info('shutting down...') logger.info('Shutting down')
def main(): p = get_argument_parser() p = ArgumentParser( description=textwrap.dedent('''\ Env Variables: CIF_RUNTIME_PATH CIF_ROUTER_CONFIG_PATH CIF_ROUTER_ADDR CIF_HUNTER_ADDR CIF_HUNTER_TOKEN CIF_HUNTER_THREADS CIF_GATHERER_THREADS CIF_STORE_ADDR example usage: $ cif-router --listen 0.0.0.0 -d '''), formatter_class=RawDescriptionHelpFormatter, prog='cif-router', parents=[p] ) p.add_argument('--config', help='specify config path [default: %(default)s', default=CONFIG_PATH) p.add_argument('--listen', help='address to listen on [default: %(default)s]', default=ROUTER_ADDR) p.add_argument('--gatherer-threads', help='specify number of gatherer threads to use [default: %(default)s]', default=GATHERER_THREADS) p.add_argument('--hunter', help='address hunters listen on on [default: %(default)s]', default=HUNTER_ADDR) p.add_argument('--hunter-token', help='specify token for hunters to use [default: %(default)s]', default=HUNTER_TOKEN) p.add_argument('--hunter-threads', help='specify number of hunter threads to use [default: %(default)s]', default=HUNTER_THREADS) p.add_argument("--store-address", help="specify the store address cif-router is listening on[default: %(" "default)s]", default=STORE_ADDR) p.add_argument("--store", help="specify a store type {} [default: %(default)s]".format(', '.join(STORE_PLUGINS)), default=STORE_DEFAULT) p.add_argument('--store-nodes', help='specify storage nodes address [default: %(default)s]', default=STORE_NODES) p.add_argument('--logging-ignore', help='set logging to WARNING for specific modules') p.add_argument('--pidfile', help='specify pidfile location [default: %(default)s]', default=PIDFILE) args = p.parse_args() setup_logging(args) logger = logging.getLogger(__name__) logger.info('loglevel is: {}'.format(logging.getLevelName(logger.getEffectiveLevel()))) if args.logging_ignore: to_ignore = args.logging_ignore.split(',') for i in to_ignore: logging.getLogger(i).setLevel(logging.WARNING) o = read_config(args) options = vars(args) for v in options: if options[v] is None: options[v] = o.get(v) setup_runtime_path(args.runtime_path) setup_signals(__name__) # http://stackoverflow.com/a/789383/7205341 pid = str(os.getpid()) logger.debug("pid: %s" % pid) if os.path.isfile(args.pidfile): logger.critical("%s already exists, exiting" % args.pidfile) raise SystemExit try: pidfile = open(args.pidfile, 'w') pidfile.write(pid) pidfile.close() except PermissionError as e: logger.error('unable to create pid %s' % args.pidfile) with Router(listen=args.listen, hunter=args.hunter, store_type=args.store, store_address=args.store_address, store_nodes=args.store_nodes, hunter_token=args.hunter_token, hunter_threads=args.hunter_threads, gatherer_threads=args.gatherer_threads) as r: try: logger.info('starting router..') r.start() except KeyboardInterrupt: # todo - signal to threads to shut down and wait for them to finish logger.info('shutting down via SIGINT...') except SystemExit: logger.info('shutting down via SystemExit...') except Exception as e: logger.critical(e) traceback.print_exc() r.stop() logger.info('Shutting down') if os.path.isfile(args.pidfile): os.unlink(args.pidfile)