Exemple #1
0
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
    __builtins__["instance"] = options.instance
    __builtins__["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
        twistd_options.append("--reactor=epoll")
    except:
        pass

    if options.debug:
        twistd_options.extend(["--nodaemon"])
    if options.profile:
        twistd_options.append("--profile")
    if options.pidfile:
        twistd_options.extend(["--pidfile", options.pidfile])

    # Now for the plugin-specific options.
    twistd_options.append(program)

    if options.debug:
        twistd_options.append("--debug")

    for option_name, option_value in vars(options).items():
        if (option_value is not None and
            option_name not in ("debug", "profile", "pidfile")):
            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)
Exemple #2
0
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
    __builtins__["instance"] = options.instance
    __builtins__["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
        twistd_options.append("--reactor=epoll")
    except:
        pass

    if options.debug:
        twistd_options.extend(["--nodaemon"])
    if options.profile:
        twistd_options.append("--profile")
    if options.pidfile:
        twistd_options.extend(["--pidfile", options.pidfile])

    # Now for the plugin-specific options.
    twistd_options.append(program)

    if options.debug:
        twistd_options.append("--debug")

    for option_name, option_value in vars(options).items():
        if (option_value is not None
                and option_name not in ("debug", "profile", "pidfile")):
            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)
def run(options):
    """ this reimplements twisted.application.app.run to use an option array, instead of argvs"""
    config = ServerOptions()
    try:
        config.parseOptions(options=options)
    except usage.error, ue:
        print config
        print "%s: %s" % (sys.argv[0], ue)
Exemple #4
0
def run():
    # parse daemon configuration
    config = ServerOptions()
    try:
        config.parseOptions()
    except usage.error, ue:
        print config
        print "%s: %s" % (sys.argv[0], ue)
        return
Exemple #5
0
def run_twistd_plugin(filename):
    from twisted.scripts.twistd import runApp
    from twisted.scripts.twistd import ServerOptions
    from rurouni.conf import get_parser

    bin_dir = dirname(abspath(filename))
    root_dir = dirname(bin_dir)
    os.environ.setdefault('GRAPHITE_ROOT', root_dir)

    program = splitext(basename(filename))[0]
    parser = get_parser()
    (options, args) = parser.parse_args()

    if not args:
        parser.print_usage()
        return

    twistd_options = []
    try:
        from twisted.internet import epollreactor
        twistd_options.append('--reactor=epoll')
    except:
        pass

    if options.debug or options.nodaemon:
        twistd_options.append('--nodaemon')
    if options.pidfile:
        twistd_options.extend(['--pidfile', options.pidfile])
    if options.umask:
        twistd_options.extend(['--umask', options.umask])

    twistd_options.append(program)

    if options.debug:
        twistd_options.append('--debug')
    for name, value in vars(options).items():
        if (value is not None and
                name not in ('debug', 'nodaemon', 'pidfile', 'umask')):
            twistd_options.extend(["--%s" % name.replace("_", '-'),
                                  value])

    twistd_options.extend(args)
    config = ServerOptions()
    config.parseOptions(twistd_options)
    runApp(config)
Exemple #6
0
    def start(self):
        log.debug("Starting Carbon..")

        twistd_options = ["--no_save", "--nodaemon", 'carbon-combined']

        if self.carbon_config_file is not None:
            twistd_options.append('--config=' + self.carbon_config_file)

        config = ServerOptions()
        config.parseOptions(twistd_options)
        config.subCommand = 'carbon-combined'

        # Hacky stuff to get carbon logging to the proper place
        from carbon.conf import settings as c_sett
        from carbon import log as c_log

        log_dir = os.path.join(os.environ['GRAPHITE_ROOT'], 'storage', 'log','carbon')
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        c_log.logToStdout()
        c_log.logToDir(log_dir)

        # Change these if you want big logs
        c_sett.LOG_UPDATES = False
        c_sett.LOG_CACHE_HITS = True



        plg = config.loadedPlugins[config.subCommand]
        self.application_service = plg.makeService(config.subOptions)

        if reactor.running:
            raise Exception('Reactor is already running.')

        self.application_service.startService()
        self.reactor_thread = self.ReactorThread()
        self.reactor_thread.start()

        log.debug("Started Carbon.")
Exemple #7
0
    def start(self):
        log.debug("Starting Carbon..")

        twistd_options = ["--no_save", "--nodaemon", 'carbon-combined']

        if self.carbon_config_file is not None:
            twistd_options.append('--config=' + self.carbon_config_file)

        config = ServerOptions()
        config.parseOptions(twistd_options)
        config.subCommand = 'carbon-combined'

        # Hacky stuff to get carbon logging to the proper place
        from carbon.conf import settings as c_sett
        from carbon import log as c_log

        log_dir = os.path.join(os.environ['GRAPHITE_ROOT'], 'storage', 'log',
                               'carbon')
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        c_log.logToStdout()
        c_log.logToDir(log_dir)

        # Change these if you want big logs
        c_sett.LOG_UPDATES = False
        c_sett.LOG_CACHE_HITS = True

        plg = config.loadedPlugins[config.subCommand]
        self.application_service = plg.makeService(config.subOptions)

        if reactor.running:
            raise Exception('Reactor is already running.')

        self.application_service.startService()
        self.reactor_thread = self.ReactorThread()
        self.reactor_thread.start()

        log.debug("Started Carbon.")
 def postOptions(self):
     """Ensure that no_save flag is always set"""
     TwistdServerOptions.postOptions(self)
     self["no_save"] = True