def configure():
    global file_dir, dane_us_connection, sleep_time, game, backup_processed_files

    parser = optparse.OptionParser()
    parser.add_option("-s", "--sleep", dest="sleep", default="5", 
                      help="time to sleep between file searches")
    parser.add_option("-d", "--shard", dest="shard", default="0", help="shard to process")
    parser.add_option("-i", "--ini", dest="ini", help="uuss ini file")
    parser.add_option("-g", "--game", dest="game", help="game to process (dane, india)")
    parser.add_option("-b", "--backup", action="store_true", help="backup processed files")
    options, args = parser.parse_args()

    sleep_time = int(options.sleep)

    game = options.game
    if game is None:
        print "game option is required"
        sys.exit(1)

    ini_file = options.ini
    if ini_file is None:
        print "ini option is required"
        sys.exit(1)

    shard = int(options.shard)

    backup_processed_files = options.backup
    
    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(ini_file, [game], {'uuss.use_gevent': False})

    file_dir = config["%s_user_state.tmp_dir%s" % (game, shard)]

    dane_us_write = config['sqlalchemy.%s_userstate%s.url' % (game, shard)]
    dane_us_connection = sa.create_engine(dane_us_write).connect()
Esempio n. 2
0
def configure(shard=None):
    import argparse

    parser = argparse.ArgumentParser(description='Run through all user ids in the state tables and check the user_ids in the states')

    parser.add_argument("-i", "--ini", help="ini file", required=True)
    parser.add_argument("-g", "--game", help="game", required=True)
    args = parser.parse_args()

    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(args.ini)

    global log
    log = logging.getLogger(__name__)

    from uuss.server import model

    game_model = getattr(model, args.game)

    if shard is not None:
#        engine = sa.engine_from_config(config, "sqlalchemy.%s_read." % args.game)
        engine = game_model.userstate_engines['userstate_shard_%i' % shard]
    else:
        engine = None
    return engine, game_model, config
Esempio n. 3
0
def configure(options):
    """
    Find the first app we got command-line options for and setup for it.
    We are only processing one app with this script, so if more than one
    is specified on the command-line, only one of them will get processed.
    No guarantees on which one that is.
    """
    global mongo_db, tmp_dir, max_batch_size, bucket, shard, cycle_time, rebalancing, game, userstate

    game = options.game
    if game is None:
        print "game option is required"
        sys.exit(1)

    ini_file = options.ini
    if ini_file is None:
        print "ini option is required"
        sys.exit(1)

    log.info('Configuring...')
        
    bucket = int(options.bucket)
    shard = int(options.shard)
    max_batch_size = int(options.batch)
    cycle_time = int(options.time)

    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(ini_file, [game], {'uuss.use_gevent': False})
    helpers.config = config

    userstate = getattr(model, game).userstate

    tmp_dir = config["%s_user_state.tmp_dir%s" % (game, shard)]
    if not os.path.exists(tmp_dir):
        os.mkdir(tmp_dir)

    rebalancing = converters.asbool(config['%s_user_state.rebalancing' % game]) and options.rebal
    if rebalancing:
        hosts = config['%s_user_state.mongo_hosts_rebal' % game].split(";")
    else:
        hosts = config['%s_user_state.mongo_hosts' % game].split(";")
    mongo_db = mongo.connect(hosts[shard])[config['%s_user_state.mongo_dbname' % game]]
Esempio n. 4
0
def start_one(args):
    from gevent import monkey
    monkey.patch_all()
    
    from gevent import event
    import threading
    threading.Event = event.Event
    
    import lolapps.common.gevent.mongodb_pool
    
    # Use the gevent socket pool for raidcache and the non-thread-local raidcache client
    from lolapps.util.adapters import raidcache
    raidcache.Client = raidcache.RaidcacheClient
    from lolapps.common.gevent import socket_pool
    raidcache.Pool = socket_pool.SocketPool

    global config

    from uuss.server import configuration
    
    (full_config, config) = configuration.init_from_ini(
        args.ini,
        # override the message sending type (we don't want to put messages back in the mq)
        overrides={ 'uums.send_message_type': 'direct'})

    import logging

    global log
    log = logging.getLogger(__name__)

    log.info('Starting uuss mq processor')

    from uuss.server import model

    import lolapps.util.mq_handler as mq_handler

    import gc
    log.info("GC collected %r objects", gc.collect())

    mq_handler.register_signal_handlers(signalhandler)
    mq_handler.start(1, model.mq, model.MQ_UUSS, handle_item, lambda: None)
Esempio n. 5
0
def configure():
    import argparse

    parser = argparse.ArgumentParser(description='Run the UUSS server.')

    parser.add_argument("-d", "--shard", help="shard to process", type=int, required=True)
    parser.add_argument("-i", "--ini", help="ini file", required=True)
    parser.add_argument("-g", "--game", help="game file", required=True)
    args = parser.parse_args()

    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(args.ini)

    global log
    log = logging.getLogger(__name__)

    from uuss.server import model

    game_model = getattr(model, args.game)

    return game_model.userstate_engines["userstate_shard_%s" % args.shard], game_model.userstate
def configure():
    global file_dirs, dane_connection, sleep_time, rebalancing, game

    parser = optparse.OptionParser()
    parser.add_option("-s", "--sleep", dest="sleep", default="5", 
                      help="time to sleep between file searches")
    parser.add_option("-d", "--shard", dest="shard", default="-1", help="shard to process")
    parser.add_option("-i", "--ini", dest="ini", help="uuss ini file")
    parser.add_option("-r", "--rebal", dest="rebal", action="store_true", default=False, 
                      help="rebalancing node")
    parser.add_option("-g", "--game", dest="game", help="game to process (dane, india)")
    options, args = parser.parse_args()

    sleep_time = int(options.sleep)

    game = options.game
    if game is None:
        print "game option is required"
        sys.exit(1)

    ini_file = options.ini
    if ini_file is None:
        print "ini option is required"
        sys.exit(1)

    shard = int(options.shard)

    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(ini_file, [game], {'uuss.use_gevent': False})

    if shard >= 0:
        file_dirs = [ config["%s_user_state.tmp_dir%s" % (shard, game)] ]
    else:
        shard_count = len(config["%s_user_state.mongo_hosts" % game].split(';'))
        file_dirs = [config["%s_user_state.tmp_dir%s" % (game, shard_index)] for shard_index in range(shard_count)]
    rebalancing = converters.asbool(config["sqlalchemy.%s_userstate.rebalancing" % game]) and options.rebal

    dane_write = config['sqlalchemy.%s.url' % game]
    dane_connection = sa.create_engine(dane_write).connect()
Esempio n. 7
0
File: run.py Progetto: brianr/uuss
def start_one(args, num=0):
    import signal
    import sys
    def handle_term(signum, frame):
        log.warn("SIGTERM caught in worker process")
        global die
        die = True

        shutdown_event.set()
        restart_or_die_event.set()

        from uuss import stats
        stats.stop()
        
        global server
        if server:
            stop()
            server = None
    signal.signal(signal.SIGTERM, handle_term)

    from gevent import monkey
    monkey.patch_all()

    import lolapps.common.gevent.mongodb_pool
    
    # Use the gevent socket pool for raidcache and the non-thread-local raidcache client
    from lolapps.util.adapters import raidcache
    raidcache.Client = raidcache.RaidcacheClient
    from lolapps.common.gevent import socket_pool
    raidcache.Pool = socket_pool.SocketPool

    global config

    from uuss.server import configuration
    
    (full_config, config) = configuration.init_from_ini(args.ini)

    import logging

    global log
    log = logging.getLogger(__name__)

    from uuss import stats
    from gevent import event
    stats.start(event.Event)

    log.info('Starting uuss server')

    global fail_healthcheck_event, unset_fail_healthcheck_event, shutdown_event, restart_or_die_event
    fail_healthcheck_event = event.Event()
    unset_fail_healthcheck_event = event.Event()
    shutdown_event = event.Event()
    restart_or_die_event = event.Event()

    from gevent import Greenlet
    Greenlet.spawn(watch_for_healthcheck_fail)
    Greenlet.spawn(watch_for_shutdown)

    import gc
    log.debug("GC collected %r objects", gc.collect())

    start_server(num)