raise SystemExit(1) destinations = [] for arg in args: parts = arg.split(':', 2) host = parts[0] port = int(parts[1]) if len(parts) > 2: instance = parts[2] else: instance = None destinations.append((host, port, instance)) if options.debug: log.logToStdout() log.setDebugEnabled(True) defer.setDebugging(True) if options.routing == 'consistent-hashing': router = ConsistentHashingRouter(options.replication, diverse_replicas=options.diverse_replicas) elif options.routing == 'relay': if exists(options.relayrules): router = RelayRulesRouter(options.relayrules) else: print("relay rules file %s does not exist" % options.relayrules) raise SystemExit(1) client_manager = CarbonClientManager(router) reactor.callWhenRunning(client_manager.startService)
def run_twistd_plugin(filename): from carbon.conf import get_parser from twisted.scripts.twistd import ServerOptions bin_dir = dirname(abspath(filename)) root_dir = dirname(bin_dir) os.environ.setdefault('GRAPHITE_ROOT', root_dir) program = basename(filename).split('.')[0] # First, parse command line options as the legacy carbon scripts used to # do. parser = get_parser(program) (options, args) = parser.parse_args() if not args: parser.print_usage() return # This isn't as evil as you might think __builtin__.instance = options.instance __builtin__.program = program # Then forward applicable options to either twistd or to the plugin itself. twistd_options = ["--no_save"] # If no reactor was selected yet, try to use the epoll reactor if # available. try: from twisted.internet import epollreactor # noqa: F401 twistd_options.append("--reactor=epoll") except ImportError: pass if options.debug or options.nodaemon: twistd_options.extend(["--nodaemon"]) if options.profile: twistd_options.extend(["--profile", options.profile]) if options.profiler: twistd_options.extend(["--profiler", options.profiler]) if options.pidfile: twistd_options.extend(["--pidfile", options.pidfile]) if options.umask: twistd_options.extend(["--umask", options.umask]) if options.logger: twistd_options.extend(["--logger", options.logger]) if options.logger: twistd_options.extend(["--logfile", options.logfile]) if options.syslog: twistd_options.append("--syslog") # Now for the plugin-specific options. twistd_options.append(program) if options.debug: twistd_options.append("--debug") setDebugEnabled(True) for option_name, option_value in vars(options).items(): if (option_value is not None and option_name not in ("debug", "profile", "profiler", "pidfile", "umask", "nodaemon", "syslog", "logger", "logfile")): twistd_options.extend( ["--%s" % option_name.replace("_", "-"), option_value]) # Finally, append extra args so that twistd has a chance to process them. twistd_options.extend(args) config = ServerOptions() config.parseOptions(twistd_options) runApp(config)
raise SystemExit(1) destinations = [] for arg in args: parts = arg.split(':', 2) host = parts[0] port = int(parts[1]) if len(parts) > 2: instance = parts[2] else: instance = None destinations.append((host, port, instance)) if options.debug: log.logToStdout() log.setDebugEnabled(True) defer.setDebugging(True) if options.routing == 'consistent-hashing': router = ConsistentHashingRouter(options.replication, diverse_replicas=options.diverse_replicas) elif options.routing == 'relay': if exists(options.relayrules): router = RelayRulesRouter(options.relayrules) else: print("relay rules file %s does not exist" % options.relayrules) raise SystemExit(1) client_manager = CarbonClientManager(router) reactor.callWhenRunning(client_manager.startService) if options.keyfunc:
def run_twistd_plugin(filename): from carbon.conf import get_parser from twisted.scripts.twistd import ServerOptions bin_dir = dirname(abspath(filename)) root_dir = dirname(bin_dir) os.environ.setdefault('GRAPHITE_ROOT', root_dir) program = basename(filename).split('.')[0] # First, parse command line options as the legacy carbon scripts used to # do. parser = get_parser(program) (options, args) = parser.parse_args() if not args: parser.print_usage() return # This isn't as evil as you might think __builtin__.instance = options.instance __builtin__.program = program # Then forward applicable options to either twistd or to the plugin itself. twistd_options = ["--no_save"] # If no reactor was selected yet, try to use the epoll reactor if # available. try: from twisted.internet import epollreactor # noqa: F401 twistd_options.append("--reactor=epoll") except ImportError: pass if options.debug or options.nodaemon: twistd_options.extend(["--nodaemon"]) if options.profile: twistd_options.extend(["--profile", options.profile]) if options.profiler: twistd_options.extend(["--profiler", options.profiler]) if options.pidfile: twistd_options.extend(["--pidfile", options.pidfile]) if options.umask: twistd_options.extend(["--umask", options.umask]) if options.logger: twistd_options.extend(["--logger", options.logger]) if options.logger: twistd_options.extend(["--logfile", options.logfile]) if options.syslog: twistd_options.append("--syslog") # Now for the plugin-specific options. twistd_options.append(program) if options.debug: twistd_options.append("--debug") setDebugEnabled(True) for option_name, option_value in vars(options).items(): if (option_value is not None and option_name not in ( "debug", "profile", "profiler", "pidfile", "umask", "nodaemon", "syslog", "logger", "logfile")): twistd_options.extend(["--%s" % option_name.replace("_", "-"), option_value]) # Finally, append extra args so that twistd has a chance to process them. twistd_options.extend(args) config = ServerOptions() config.parseOptions(twistd_options) runApp(config)