示例#1
0
 def _dispatch_callback_future(self, msg, cid, mid, cast, cmd_name, send_resp, future):
     exception = check_future_exception_and_log(future)
     if exception is not None:
         if send_resp:
             self.send_error(mid, cid, msg, "server error", cast=cast, errno=errors.BAD_MSG_DATA_ERROR)
     else:
         resp = future.result()
         if send_resp:
             self._dispatch_callback(msg, cid, mid, cast, cmd_name, resp)
示例#2
0
 def _dispatch_callback_future(self, msg, cid, mid, cast, cmd_name,
                               send_resp, future):
     exception = check_future_exception_and_log(future)
     if exception is not None:
         if send_resp:
             self.send_error(mid, cid, msg, "server error", cast=cast,
                             errno=errors.BAD_MSG_DATA_ERROR)
     else:
         resp = future.result()
         if send_resp:
             self._dispatch_callback(msg, cid, mid, cast, cmd_name, resp)
示例#3
0
def start(profile):
    tamer = DaemonTamer(profile)
    daemonize()
    arbiter = tamer.make_arbiter()
    restart = True
    while restart:
        try:
            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
    sys.exit(0)
示例#4
0
def start():
    daemonize()
    # ~ arbiter = get_arbiter([get_streamer('bla')],
                          # ~ controller='tcp://127.0.0.1:6000',
                          # ~ logoutput='arbiter.log', loglevel='INFO', debug=False, statsd=True)
    arbiter = get_arbiter([get_daemon_properties('ricoh')],
                          controller='tcp://127.0.0.1:6000',
                          logoutput='arbiter.log', loglevel='INFO', debug=False, statsd=True)
    restart = True
    while restart:
        try:
            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
    sys.exit(0)
示例#5
0
def main(profile, loggerconfig, foreground, pidfile):
    """Run an aiida daemon"""
    import zmq
    try:
        zmq_version = [int(part) for part in zmq.__version__.split('.')[:2]]
        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)

    loglevel = 'INFO'
    logoutput = '-'

    if not foreground:
        logoutput = 'balrog-{}.log'.format(profile)
        daemonize()

    # Create the arbiter
    profile_config = ProfileConfig(profile)

    arbiter = get_arbiter(
        controller=profile_config.get_endpoint(0),
        pubsub_endpoint=profile_config.get_endpoint(1),
        stats_endpoint=profile_config.get_endpoint(2),
        logoutput=logoutput,
        loglevel=loglevel,
        debug=False,
        statsd=True,
        pidfile='balrog-{}.pid'.format(
            profile
        ),  # aiida.common.setup.AIIDA_CONFIG_FOLDER + '/daemon/aiida-{}.pid'.format(uuid)
        watchers=[{
            'name': profile_config.daemon_name,
            'cmd': profile_config.cmd_string,
            'virtualenv': VIRTUALENV,
            'copy_env': True,
            'stdout_stream': {
                'class': 'FileStream',
                'filename': '{}.log'.format(profile_config.daemon_name)
            },
            'env': {
                'PYTHONUNBUFFERED': 'True'
            }
        }])

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

    pidfile = 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 = loglevel or arbiter.loglevel or 'info'
    logoutput = logoutput or arbiter.logoutput or '-'
    loggerconfig = loggerconfig or arbiter.loggerconfig or None
    configure_logger(logger, loglevel, logoutput, loggerconfig)

    # Main loop
    restart = True
    while restart:
        try:
            arbiter = arbiter
            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)
示例#6
0
def _start_circus(foreground):
    """
    This will actually launch the circus daemon, either daemonized in the background
    or in the foreground, printing all logs to stdout.

    .. note:: this should not be called directly from the commandline!
    """
    from circus import get_arbiter
    from circus import logger as circus_logger
    from circus.circusd import daemonize
    from circus.pidfile import Pidfile
    from circus.util import check_future_exception_and_log, configure_logger

    client = DaemonClient()

    loglevel = client.loglevel
    logoutput = '-'

    if not foreground:
        logoutput = client.circus_log_file

    arbiter_config = {
        'controller': client.get_controller_endpoint(),
        'pubsub_endpoint': client.get_pubsub_endpoint(),
        'stats_endpoint': client.get_stats_endpoint(),
        'logoutput': logoutput,
        'loglevel': loglevel,
        'debug': False,
        'statsd': True,
        'pidfile': client.circus_pid_file,
        'watchers': [{
            'name': client.daemon_name,
            'cmd': client.cmd_string,
            'virtualenv': client.virtualenv,
            'copy_env': True,
            'stdout_stream': {
                'class': 'FileStream',
                'filename': client.daemon_log_file,
            },
            'env': get_env_with_venv_bin(),
        }]
    } # yapf: disable

    if not foreground:
        daemonize()

    arbiter = get_arbiter(**arbiter_config)
    pidfile = Pidfile(arbiter.pidfile)

    try:
        pidfile.create(os.getpid())
    except RuntimeError as exception:
        click.echo(str(exception))
        sys.exit(1)

    # Configure the logger
    loggerconfig = None
    loggerconfig = loggerconfig or arbiter.loggerconfig or None
    configure_logger(circus_logger, loglevel, logoutput, loggerconfig)

    # Main loop
    should_restart = True

    while should_restart:
        try:
            arbiter = arbiter
            future = arbiter.start()
            should_restart = False
            if check_future_exception_and_log(future) is None:
                should_restart = arbiter._restarting  # pylint: disable=protected-access
        except Exception as exception:
            # Emergency stop
            arbiter.loop.run_sync(arbiter._emergency_stop)  # pylint: disable=protected-access
            raise exception
        except KeyboardInterrupt:
            pass
        finally:
            arbiter = None
            if pidfile is not None:
                pidfile.unlink()

    sys.exit(0)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
0
    #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)


if __name__ == '__main__':
    main()
示例#11
0
    #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)


if __name__ == '__main__':
    main()
示例#12
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)
示例#13
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)