コード例 #1
0
ファイル: circushttpd.py プロジェクト: nathancahill/circus
def main():
    parser = argparse.ArgumentParser(description='Run the Web Console')

    parser.add_argument('--fd', help='FD', default=None)
    parser.add_argument('--host', help='Host', default='0.0.0.0')
    parser.add_argument('--port', help='port', default=8080)
    parser.add_argument('--server', help='web server to use',
                        default=SocketIOServer)
    parser.add_argument('--endpoint', default=None,
        help='Circus Endpoint. If not specified, Circus will ask you which '
             'system you want to connect to')
    parser.add_argument('--version', action='store_true',
                     default=False, help='Displays Circus version and exits.')
    parser.add_argument('--log-level', dest='loglevel', default='info',
            choices=LOG_LEVELS.keys() + [key.upper() for key in
                LOG_LEVELS.keys()],
            help="log level")
    parser.add_argument('--log-output', dest='logoutput', default='-',
            help="log output")
    parser.add_argument('--ssh', default=None, help='SSH Server')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    if args.endpoint is not None:
        connect_to_circus(args.endpoint, args.ssh)

    run(app, host=args.host, port=args.port, server=args.server, fd=args.fd)
コード例 #2
0
def main():
    parser = argparse.ArgumentParser(description='Run the Web Console')

    parser.add_argument('--fd', help='FD', default=None)
    parser.add_argument('--host', help='Host', default='0.0.0.0')
    parser.add_argument('--port', help='port', default=8080)
    parser.add_argument('--server',
                        help='web server to use',
                        default=SocketIOServer)
    parser.add_argument('--endpoint',
                        default=None,
                        help='Circus Endpoint. If not specified, Circus will '
                        'ask you which system you want to connect to')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')
    parser.add_argument('--log-level',
                        dest='loglevel',
                        default='info',
                        choices=LOG_LEVELS.keys() +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output',
                        dest='logoutput',
                        default='-',
                        help="log output")
    parser.add_argument('--ssh', default=None, help='SSH Server')
    parser.add_argument('--multicast',
                        dest="multicast",
                        default="udp://237.219.251.97:12027",
                        help="Multicast endpoint. If not specified, Circus "
                        "will use default one")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    if args.endpoint is not None:
        connect_to_circus(args.endpoint, args.ssh)

    try:
        sys.stderr.write(' ')
        quiet = False
    except IOError:
        quiet = True

    setup_auto_discovery(args.multicast)
    run(app,
        host=args.host,
        port=args.port,
        server=args.server,
        fd=args.fd,
        quiet=quiet)
コード例 #3
0
ファイル: circusd.py プロジェクト: amarandon/circus
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level',
                        dest='loglevel',
                        choices=LOG_LEVELS.keys() +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument(
        '--log-output',
        dest='logoutput',
        help=(
            "The location where the logs will be written. The default behavior "
            "is to write to stdout (you can force it by passing '-' to "
            "this option). Takes a filename otherwise."))

    parser.add_argument('--daemon',
                        dest='daemonize',
                        action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # basic logging configuration
    logging.basicConfig()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)
コード例 #4
0
ファイル: circushttpd.py プロジェクト: mithro/circus-web
def main():
    define("port", default=8080, type=int)
    parser = argparse.ArgumentParser(description='Run the Web Console')

    parser.add_argument('--fd', help='FD', default=None, type=int)
    parser.add_argument('--host', help='Host', default='0.0.0.0')
    parser.add_argument('--port', help='port', default=8080)
    parser.add_argument('--endpoint', default=None,
                        help='Circus Endpoint. If not specified, Circus will '
                             'ask you which system you want to connect to')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')
    parser.add_argument('--log-level', dest='loglevel', default='info',
                        choices=LOG_LEVELS.keys() + [key.upper() for key in
                                                     LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', default='-',
                        help="log output")
    parser.add_argument('--ssh', default=None, help='SSH Server')
    parser.add_argument('--multicast', dest="multicast",
                        default="udp://237.219.251.97:12027",
                        help="Multicast endpoint. If not specified, Circus "
                             "will use default one")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    # Get the tornado ioloop singleton
    loop = tornado.ioloop.IOLoop.instance()

    if args.endpoint is not None:
        connect_to_circus(loop, args.endpoint, args.ssh)

    app.auto_discovery = AutoDiscovery(args.multicast, loop)
    http_server = tornado.httpserver.HTTPServer(app)

    if args.fd:
        sock = socket.fromfd(args.fd, socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setblocking(0)
        http_server.add_sockets([sock])
        logger.info("Starting circus web ui on fd %d" % args.fd)
    else:
        http_server.listen(args.port, args.host)
        logger.info("Starting circus web ui on %s:%s" % (args.host, args.port))

    loop.start()
コード例 #5
0
ファイル: circusd.py プロジェクト: alessandrod/circus
def main():
    parser = argparse.ArgumentParser(description="Run some watchers.")
    parser.add_argument("config", help="configuration file", nargs="?")

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument(
        "--log-level",
        dest="loglevel",
        default="info",
        choices=LOG_LEVELS.keys() + [key.upper() for key in LOG_LEVELS.keys()],
        help="log level",
    )
    parser.add_argument(
        "--log-output",
        dest="logoutput",
        default="-",
        help=(
            "The location where the logs will be written. The default behavior "
            "is to write to stdout (you can force it by passing '-' to "
            "this option). Takes a filename otherwise."
        ),
    )

    parser.add_argument("--daemon", dest="daemonize", action="store_true", help="Start circusd in the background")
    parser.add_argument("--pidfile", dest="pidfile")
    parser.add_argument("--version", action="store_true", default=False, help="Displays Circus version and exits.")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    pidfile = None
    if args.pidfile:
        pidfile = Pidfile(args.pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)
コード例 #6
0
ファイル: circusd.py プロジェクト: strategist922/circus
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level', dest='loglevel',
                        choices=LOG_LEVELS.keys() + [key.upper() for key in
                                                     LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', help=(
        "The location where the logs will be written. The default behavior "
        "is to write to stdout (you can force it by passing '-' to "
        "this option). Takes a filename otherwise."))

    parser.add_argument('--daemon', dest='daemonize', action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # basic logging configuration
    logging.basicConfig()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)
コード例 #7
0
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level',
                        dest='loglevel',
                        default='info',
                        choices=LOG_LEVELS.keys() +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output',
                        dest='logoutput',
                        default='-',
                        help="log output")
    parser.add_argument('--daemon',
                        dest='daemonize',
                        action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    pidfile = None
    if args.pidfile:
        pidfile = Pidfile(args.pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)
コード例 #8
0
ファイル: __init__.py プロジェクト: nabeelio/circus
def main():
    parser = argparse.ArgumentParser(description="Runs a plugin.")

    parser.add_argument("--endpoint", help="The circusd ZeroMQ socket to connect to", default=DEFAULT_ENDPOINT_DEALER)

    parser.add_argument(
        "--pubsub", help="The circusd ZeroMQ pub/sub socket to connect to", default=DEFAULT_ENDPOINT_SUB
    )

    parser.add_argument("--config", help="The plugin configuration", default=None)

    parser.add_argument("--version", action="store_true", default=False, help="Displays Circus version and exits.")

    parser.add_argument("--check-delay", type=float, default=5.0, help="Checck delay.")

    parser.add_argument("plugin", help="Fully qualified name of the plugin class.", nargs="?")

    parser.add_argument("--log-level", dest="loglevel", default="info", help="log level")

    parser.add_argument("--log-output", dest="logoutput", default="-", help="log output")

    parser.add_argument("--ssh", default=None, help="SSH Server")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.plugin is None:
        parser.print_usage()
        sys.exit(0)

    # configure the logger
    loglevel = LOG_LEVELS.get(args.loglevel.lower(), logging.INFO)
    logger.setLevel(loglevel)
    if args.logoutput == "-":
        h = logging.StreamHandler()
    else:
        h = logging.handlers.WatchedFileHandler(args.logoutput)
        close_on_exec(h.stream.fileno())
    fmt = logging.Formatter(LOG_FMT, LOG_DATE_FMT)
    h.setFormatter(fmt)
    logger.addHandler(h)

    # load the plugin and run it.
    logger.info("Loading the plugin...")
    logger.info("Endpoint: %r" % args.endpoint)
    logger.info("Pub/sub: %r" % args.pubsub)
    plugin = resolve_name(args.plugin)(args.endpoint, args.pubsub, args.check_delay, args.ssh, **_str2cfg(args.config))
    logger.info("Starting")
    try:
        plugin.start()
    except KeyboardInterrupt:
        pass
    finally:
        logger.info("Stopping")
        plugin.stop()
    sys.exit(0)
コード例 #9
0
ファイル: circushttpd.py プロジェクト: jarus/circus-web
def main():
    parser = argparse.ArgumentParser(description='Run the Web Console')

    parser.add_argument('--fd', help='FD', default=None)
    parser.add_argument('--host', help='Host', default='0.0.0.0')
    parser.add_argument('--port', help='port', default=8080)
    parser.add_argument('--server', help='web server to use',
                        default=SocketIOServer)
    parser.add_argument('--endpoint', default=None,
                        help='Circus Endpoint. If not specified, Circus will '
                             'ask you which system you want to connect to')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')
    parser.add_argument('--log-level', dest='loglevel', default='info',
                        choices=LOG_LEVELS.keys() + [key.upper() for key in
                                                     LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', default='-',
                        help="log output")
    parser.add_argument('--ssh', default=None, help='SSH Server')
    parser.add_argument('--multicast', dest="multicast",
                        default="udp://237.219.251.97:12027",
                        help="Multicast endpoint. If not specified, Circus "
                             "will use default one")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    if args.endpoint is not None:
        connect_to_circus(args.endpoint, args.ssh)

    try:
        sys.stderr.write(' ')
        quiet = False
    except IOError:
        quiet = True

    setup_auto_discovery(args.multicast)
    run(app, host=args.host, port=args.port, server=args.server,
        fd=args.fd, quiet=quiet)
コード例 #10
0
ファイル: circusd.py プロジェクト: Jud/circus
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level', dest='loglevel', default='info',
                        choices=LOG_LEVELS.keys() + [key.upper() for key in
                                                     LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', default='-',
                        help="log output")
    parser.add_argument('--daemon', dest='daemonize', action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    pidfile = None
    if args.pidfile:
        pidfile = Pidfile(args.pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)
コード例 #11
0
    if args.daemonize:
        daemonize()

    pidfile = None
    if args.pidfile:
        pidfile = Pidfile(args.pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = LOG_LEVELS.get(args.loglevel.lower(), logging.INFO)
    logger.setLevel(loglevel)
    if args.logoutput == "-":
        h = logging.StreamHandler()
    else:
        h = logging.FileHandler(args.logoutput)
        util.close_on_exec(h.stream.fileno())
    fmt = logging.Formatter(LOG_FMT, LOG_DATE_FMT)
    h.setFormatter(fmt)
    logger.addHandler(h)

    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)
    try:
        arbiter.start()
    except KeyboardInterrupt:
コード例 #12
0
ファイル: circusd.py プロジェクト: stic/circus
def main():
    import zmq
    try:
        zmq_version = [int(part) for part in zmq.__version__.split('.')]
        if len(zmq_version) < 2:
            raise ValueError()
    except (AttributeError, ValueError):
        print('Unknown PyZQM version - aborting...')
        sys.exit(0)

    if zmq_version[0] < 13 or (zmq_version[0] == 13 and zmq_version[1] < 1):
        print('circusd needs PyZMQ >= 13.1.0 to run - aborting...')
        sys.exit(0)

    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level',
                        dest='loglevel',
                        choices=list(LOG_LEVELS.keys()) +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument(
        '--log-output',
        dest='logoutput',
        help=(
            "The location where the logs will be written. The default behavior "
            "is to write to stdout (you can force it by passing '-' to "
            "this option). Takes a filename otherwise."))
    parser.add_argument(
        "--logger-config",
        dest="loggerconfig",
        help=("The location where a standard Python logger configuration INI, "
              "JSON or YAML file can be found.  This can be used to override "
              "the default logging configuration for the arbiter."))

    parser.add_argument('--daemon',
                        dest='daemonize',
                        action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    # go ahead and set umask early if it is in the config
    if arbiter.umask is not None:
        os.umask(arbiter.umask)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError as e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = args.loglevel or arbiter.loglevel or 'info'
    logoutput = args.logoutput or arbiter.logoutput or '-'
    loggerconfig = args.loggerconfig or arbiter.loggerconfig or None
    configure_logger(logger, loglevel, logoutput, loggerconfig)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = arbiter or Arbiter.load_from_config(args.config)
            future = arbiter.start()
            restart = False
            if check_future_exception_and_log(future) is None:
                restart = arbiter._restarting
        except Exception as e:
            # emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)
            raise (e)
        except KeyboardInterrupt:
            pass
        finally:
            arbiter = None
            if pidfile is not None:
                pidfile.unlink()
    sys.exit(0)
コード例 #13
0
def main():
    parser = argparse.ArgumentParser(description='Runs a plugin.')

    parser.add_argument('--endpoint',
                        help='The circusd ZeroMQ socket to connect to',
                        default=DEFAULT_ENDPOINT_DEALER)

    parser.add_argument('--pubsub',
                        help='The circusd ZeroMQ pub/sub socket to connect to',
                        default=DEFAULT_ENDPOINT_SUB)

    parser.add_argument('--config',
                        help='The plugin configuration',
                        default=None)

    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    parser.add_argument('--check-delay',
                        type=float,
                        default=5.,
                        help='Checck delay.')

    parser.add_argument('plugin',
                        help='Fully qualified name of the plugin class.',
                        nargs='?')

    parser.add_argument('--log-level',
                        dest='loglevel',
                        default='info',
                        help="log level")

    parser.add_argument('--log-output',
                        dest='logoutput',
                        default='-',
                        help="log output")

    parser.add_argument('--ssh', default=None, help='SSH Server')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.plugin is None:
        parser.print_usage()
        sys.exit(0)

    # configure the logger
    logging.basicConfig()
    loglevel = LOG_LEVELS.get(args.loglevel.lower(), logging.INFO)
    logger.setLevel(loglevel)
    if args.logoutput == "-":
        h = logging.StreamHandler()
    else:
        h = logging.FileHandler(args.logoutput)
        close_on_exec(h.stream.fileno())
    fmt = logging.Formatter(LOG_FMT, LOG_DATE_FMT)
    h.setFormatter(fmt)
    logger.addHandler(h)

    # load the plugin and run it.
    logger.info('Loading the plugin...')
    logger.info('Endpoint: %r' % args.endpoint)
    logger.info('Pub/sub: %r' % args.pubsub)
    plugin = resolve_name(args.plugin)(args.endpoint, args.pubsub,
                                       args.check_delay, args.ssh,
                                       **_str2cfg(args.config))
    logger.info('Starting')
    try:
        plugin.start()
    except KeyboardInterrupt:
        pass
    finally:
        logger.info('Stopping')
        plugin.stop()
    sys.exit(0)
コード例 #14
0
ファイル: circusd.py プロジェクト: jwal/circus
def main():
    import zmq

    try:
        zmq_version = [int(part) for part in zmq.__version__.split(".")]
        if len(zmq_version) < 2:
            raise ValueError()
    except (AttributeError, ValueError):
        print("Unknown PyZQM version - aborting...")
        sys.exit(0)

    if zmq_version[0] < 13 or (zmq_version[0] == 13 and zmq_version[1] < 1):
        print("circusd needs PyZMQ >= 13.1.0 to run - aborting...")
        sys.exit(0)

    parser = argparse.ArgumentParser(description="Run some watchers.")
    parser.add_argument("config", help="configuration file", nargs="?")

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument(
        "--log-level",
        dest="loglevel",
        choices=list(LOG_LEVELS.keys()) + [key.upper() for key in LOG_LEVELS.keys()],
        help="log level",
    )
    parser.add_argument(
        "--log-output",
        dest="logoutput",
        help=(
            "The location where the logs will be written. The default behavior "
            "is to write to stdout (you can force it by passing '-' to "
            "this option). Takes a filename otherwise."
        ),
    )
    parser.add_argument(
        "--logger-config",
        dest="loggerconfig",
        help=(
            "The location where a standard Python logger configuration INI, "
            "JSON or YAML file can be found.  This can be used to override "
            "the default logging configuration for the arbiter."
        ),
    )

    parser.add_argument("--daemon", dest="daemonize", action="store_true", help="Start circusd in the background")
    parser.add_argument("--pidfile", dest="pidfile")
    parser.add_argument("--version", action="store_true", default=False, help="Displays Circus version and exits.")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    # go ahead and set umask early if it is in the config
    if arbiter.umask is not None:
        os.umask(arbiter.umask)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError as e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = args.loglevel or arbiter.loglevel or "info"
    logoutput = args.logoutput or arbiter.logoutput or "-"
    loggerconfig = args.loggerconfig or arbiter.loggerconfig or None
    configure_logger(logger, loglevel, logoutput, loggerconfig)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = arbiter or Arbiter.load_from_config(args.config)
            future = arbiter.start()
            restart = False
            if check_future_exception_and_log(future) is None:
                restart = arbiter._restarting
        except Exception as e:
            # emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)
            raise (e)
        except KeyboardInterrupt:
            pass
        finally:
            arbiter = None
            if pidfile is not None:
                pidfile.unlink()
    sys.exit(0)
コード例 #15
0
def main():
    define("port", default=8080, type=int)
    parser = argparse.ArgumentParser(description='Run the Web Console')

    parser.add_argument('--fd', help='FD', default=None, type=int)
    parser.add_argument('--host', help='Host', default='0.0.0.0')
    parser.add_argument('--port', help='port', default=8080)
    parser.add_argument('--endpoint',
                        default=None,
                        help='Circus Endpoint. If not specified, Circus will '
                        'ask you which system you want to connect to')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')
    parser.add_argument('--log-level',
                        dest='loglevel',
                        default='info',
                        choices=list(LOG_LEVELS.keys()) +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output',
                        dest='logoutput',
                        default='-',
                        help="log output")
    parser.add_argument('--ssh', default=None, help='SSH Server')
    parser.add_argument('--multicast',
                        dest="multicast",
                        default="udp://237.219.251.97:12027",
                        help="Multicast endpoint. If not specified, Circus "
                        "will use default one")

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    # Get the tornado ioloop singleton
    loop = tornado.ioloop.IOLoop.instance()

    if args.endpoint is not None:
        connect_to_circus(loop, args.endpoint, args.ssh)

    app.auto_discovery = AutoDiscovery(args.multicast, loop)
    http_server = tornado.httpserver.HTTPServer(app, xheaders=True)

    if args.fd:
        sock = socket.fromfd(args.fd, socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setblocking(0)
        http_server.add_sockets([sock])
        logger.info("Starting circus web ui on fd %d" % args.fd)
    else:
        http_server.listen(args.port, args.host)
        logger.info("Starting circus web ui on %s:%s" % (args.host, args.port))

    loop.start()
コード例 #16
0
ファイル: circusd.py プロジェクト: KristianOellegaard/circus
    if args.daemonize:
        daemonize()

    pidfile = None
    if args.pidfile:
        pidfile = Pidfile(args.pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError, e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = LOG_LEVELS.get(args.loglevel.lower(), logging.INFO)
    logger.setLevel(loglevel)
    if args.logoutput == "-":
        h = logging.StreamHandler()
    else:
        h = logging.FileHandler(args.logoutput)
        util.close_on_exec(h.stream.fileno())
    fmt = logging.Formatter(LOG_FMT, LOG_DATE_FMT)
    h.setFormatter(fmt)
    logger.addHandler(h)

    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)
    try:
        arbiter.start()
    except KeyboardInterrupt:
コード例 #17
0
ファイル: circusd.py プロジェクト: cdugz/circus
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level', dest='loglevel',
                        choices=list(LOG_LEVELS.keys()) + [
                            key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', help=(
        "The location where the logs will be written. The default behavior "
        "is to write to stdout (you can force it by passing '-' to "
        "this option). Takes a filename otherwise."))

    parser.add_argument('--daemon', dest='daemonize', action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # basic logging configuration
    logging.basicConfig()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError as e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = args.loglevel or arbiter.loglevel or 'info'
    logoutput = args.logoutput or arbiter.logoutput or '-'
    configure_logger(logger, loglevel, logoutput)

    # configure the main loop
    #ioloop.install()
    #loop = ioloop.IOLoop.instance()
    #cb = functools.partial(manage_restart, loop, arbiter)
    #periodic = tornado.ioloop.PeriodicCallback(cb, 1000, loop)
    #periodic.start()

    # schedule the arbiter start
    #arbiter = Arbiter.load_from_config(args.config, loop=loop)
    #loop.add_future(arbiter.start(), _arbiter_start_cb)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = Arbiter.load_from_config(args.config)
            future = arbiter.start()
            restart = False
            if check_future_exception_and_log(future) is None:
                restart = arbiter._restarting
        except Exception as e:
            # emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)
            raise(e)
        except KeyboardInterrupt:
            pass
        finally:
            if pidfile is not None:
                pidfile.unlink()
    sys.exit(0)
コード例 #18
0
ファイル: circusd.py プロジェクト: SEJeff/circus
def main():
    import zmq
    try:
        zmq_version = [int(part) for part in zmq.__version__.split('.')]
        if len(zmq_version) < 2:
            raise ValueError()
    except (AttributeError, ValueError):
        print('Unknown PyZQM version - aborting...')
        sys.exit(0)

    if zmq_version[0] < 13 or (zmq_version[0] == 13 and zmq_version[1] < 1):
        print('circusd needs PyZMQ >= 13.1.0 to run - aborting...')
        sys.exit(0)

    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level', dest='loglevel',
                        choices=list(LOG_LEVELS.keys()) + [
                            key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument('--log-output', dest='logoutput', help=(
        "The location where the logs will be written. The default behavior "
        "is to write to stdout (you can force it by passing '-' to "
        "this option). Takes a filename otherwise."))

    parser.add_argument('--daemon', dest='daemonize', action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # This config call is done to avoid any
    #     "no handlers could be found for logger"
    #
    # error while loding the configuration and setting up the arbiter.
    # The real logging configuration is done right after via
    # a configure_logger() call
    logging.basicConfig()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    # go ahead and set umask early if it is in the config
    if arbiter.umask is not None:
        os.umask(arbiter.umask)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError as e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = args.loglevel or arbiter.loglevel or 'info'
    logoutput = args.logoutput or arbiter.logoutput or '-'
    configure_logger(logger, loglevel, logoutput)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = arbiter or Arbiter.load_from_config(args.config)
            future = arbiter.start()
            restart = False
            if check_future_exception_and_log(future) is None:
                restart = arbiter._restarting
        except Exception as e:
            # emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)
            raise(e)
        except KeyboardInterrupt:
            pass
        finally:
            arbiter = None
            if pidfile is not None:
                pidfile.unlink()
    sys.exit(0)
コード例 #19
0
ファイル: __init__.py プロジェクト: jsbronder/circus
def main():
    parser = argparse.ArgumentParser(description='Runs a plugin.')

    parser.add_argument('--endpoint',
                        help='The circusd ZeroMQ socket to connect to',
                        default=DEFAULT_ENDPOINT_DEALER)

    parser.add_argument('--pubsub',
                        help='The circusd ZeroMQ pub/sub socket to connect to',
                        default=DEFAULT_ENDPOINT_SUB)

    parser.add_argument('--config', help='The plugin configuration',
                        default=None)

    parser.add_argument('--version', action='store_true', default=False,
                        help='Displays Circus version and exits.')

    parser.add_argument('--check-delay', type=float, default=5.,
                        help='Checck delay.')

    parser.add_argument('plugin',
                        help='Fully qualified name of the plugin class.',
                        nargs='?')

    parser.add_argument('--log-level', dest='loglevel', default='info',
                        help="log level")

    parser.add_argument('--log-output', dest='logoutput', default='-',
                        help="log output")

    parser.add_argument('--ssh', default=None, help='SSH Server')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.plugin is None:
        parser.print_usage()
        sys.exit(0)

    # configure the logger
    logging.basicConfig()
    loglevel = LOG_LEVELS.get(args.loglevel.lower(), logging.INFO)
    logger.setLevel(loglevel)
    if args.logoutput == "-":
        h = logging.StreamHandler()
    else:
        h = logging.FileHandler(args.logoutput)
        close_on_exec(h.stream.fileno())
    fmt = logging.Formatter(LOG_FMT, LOG_DATE_FMT)
    h.setFormatter(fmt)
    logger.addHandler(h)

    # load the plugin and run it.
    logger.info('Loading the plugin...')
    logger.info('Endpoint: %r' % args.endpoint)
    logger.info('Pub/sub: %r' % args.pubsub)
    plugin = resolve_name(args.plugin)(args.endpoint, args.pubsub,
                                       args.check_delay, args.ssh,
                                       **_str2cfg(args.config))
    logger.info('Starting')
    try:
        plugin.start()
    except KeyboardInterrupt:
        pass
    finally:
        logger.info('Stopping')
        plugin.stop()
    sys.exit(0)
コード例 #20
0
ファイル: circusd.py プロジェクト: cdgz/circus
def main():
    parser = argparse.ArgumentParser(description='Run some watchers.')
    parser.add_argument('config', help='configuration file', nargs='?')

    # XXX we should be able to add all these options in the config file as well
    parser.add_argument('--log-level',
                        dest='loglevel',
                        choices=list(LOG_LEVELS.keys()) +
                        [key.upper() for key in LOG_LEVELS.keys()],
                        help="log level")
    parser.add_argument(
        '--log-output',
        dest='logoutput',
        help=(
            "The location where the logs will be written. The default behavior "
            "is to write to stdout (you can force it by passing '-' to "
            "this option). Takes a filename otherwise."))

    parser.add_argument('--daemon',
                        dest='daemonize',
                        action='store_true',
                        help="Start circusd in the background")
    parser.add_argument('--pidfile', dest='pidfile')
    parser.add_argument('--version',
                        action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    if args.config is None:
        parser.print_usage()
        sys.exit(0)

    if args.daemonize:
        daemonize()

    # basic logging configuration
    logging.basicConfig()

    # From here it can also come from the arbiter configuration
    # load the arbiter from config
    arbiter = Arbiter.load_from_config(args.config)

    pidfile = args.pidfile or arbiter.pidfile or None
    if pidfile:
        pidfile = Pidfile(pidfile)

        try:
            pidfile.create(os.getpid())
        except RuntimeError as e:
            print(str(e))
            sys.exit(1)

    # configure the logger
    loglevel = args.loglevel or arbiter.loglevel or 'info'
    logoutput = args.logoutput or arbiter.logoutput or '-'
    configure_logger(logger, loglevel, logoutput)

    # configure the main loop
    #ioloop.install()
    #loop = ioloop.IOLoop.instance()
    #cb = functools.partial(manage_restart, loop, arbiter)
    #periodic = tornado.ioloop.PeriodicCallback(cb, 1000, loop)
    #periodic.start()

    # schedule the arbiter start
    #arbiter = Arbiter.load_from_config(args.config, loop=loop)
    #loop.add_future(arbiter.start(), _arbiter_start_cb)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = Arbiter.load_from_config(args.config)
            future = arbiter.start()
            restart = False
            if check_future_exception_and_log(future) is None:
                restart = arbiter._restarting
        except Exception as e:
            # emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)
            raise (e)
        except KeyboardInterrupt:
            pass
        finally:
            if pidfile is not None:
                pidfile.unlink()
    sys.exit(0)