Beispiel #1
0
def run_server(args):
    ioloop = IOLoop.current()
    path   = os.path.dirname(os.path.realpath(__file__))
    settings = {
        'template_path': path + os.sep + 'templates',
        'port': args.port,
    }
    app = Application([
        url(r"/ws", WsHandler),
        url(r"/", TraceHandler),
        ],
        **settings
    )
    app.listen(args.port)
    app.clients = {}
    ioloop.start()
Beispiel #2
0
def main():

    global config, logger, msg_queue, app

    logger = logging.getLogger('hedwig.nest')
    msg_queue = Queue(maxsize=2)
    app = Application([
        (r"/", MainHandler),
    ])
    config = {}

    try:
        opts, _ = getopt.gnu_getopt(sys.argv[1:], "vc:", ["version", "config"])
    except getopt.GetoptError as _:
        print("Usage: hedwig -c config")
        sys.exit(2)

    configFile = './nest.conf.yml'
    for opt, arg in opts:
        if opt == '-v':
            print(__version__)
            sys.exit()
        elif opt == '-c' or opt == '--config':
            configFile = arg
            break

    with open(configFile, 'r') as f:
        config = yaml.load(f)

    # 设定 Logging
    logging.basicConfig(format='[%(levelname)s] %(message)s')
    if config.get('debug', False):
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    app.clients = config.get('clients', {})
    listen_config = config.get('listen', { 'host': '0.0.0.0', 'port': 80 })
    app.listen(port=listen_config['port'], address=listen_config['host'])

    logger.info('Hedwig Nest is on {host}:{port}...'.format(
        host=listen_config['host'], port=listen_config['port']))

    IOLoop.current().spawn_callback(message_consumer)
    IOLoop.current().start()