Esempio n. 1
0
    handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y)))
    handlers.append((r"/(.*)", ZoneHandler))

    import tornado
    from tornado.options import options, define
    define("dburi", default='sqlite:///simplemmo.sqlite', help="Where is the database?", type=str)

    tornado.options.parse_command_line()
    dburi = options.dburi

    # Connect to the elixir db
    from elixir_models import setup
    setup(db_uri=dburi)

    # On startup, iterate through entries in zones table. See if they are up, if not, delete them.
    for port in [z[0] for z in session.query(Zone.port).all()]:
        serverurl = "%s://%s:%d" % (PROTOCOL, HOSTNAME, port)
        try:
            requests.get(serverurl)
        except(requests.ConnectionError):
            # Server is down, remove it from the zones table.
            Zone.query.filter_by(port=port).delete(), Zone
        session.commit()

    server = BaseServer(handlers)
    server.listen(MASTERZONESERVERPORT)

    print "Starting up Master Zoneserver..."
    try:
        server.start()
    except KeyboardInterrupt:
    finally:
        session.commit()
        return retval

def start_zone(port=1300, zonename="defaultzone", instancetype="playerinstance", owner="Groxnor", processgroup='zones', autorestart=False):
    s = xmlrpclib.ServerProxy('http://localhost:9001')

    import socket
    try:
        version = s.twiddler.getAPIVersion()
    except(socket.error), exc:
        raise UserWarning("Could not connect to supervisor: %s" % exc)

    if float(version) >= 0.3:
        # Query through all our zones to get a good port number.
        taken_ports = [p[0] for p in session.query(Zone.port).all()]
        for port in xrange(ZONESTARTPORT, ZONEENDPORT):
            if port not in taken_ports:
                break
        print "Chose port # %d" % port

        command = '/usr/bin/python zoneserver.py --port=%d --zonename=%s --instancetype=%s --owner=%s' % (int(port), zonename, instancetype, owner)
        zoneid = '-'.join((instancetype, zonename, owner))
        settings = {'command': command, 'autostart': str(True), 'autorestart': str(autorestart), 'redirect_stderr': str(True)}
        addtogroup = _add_process(s, processgroup, zoneid, settings, port)

        # Start up a scriptserver:
        settings['command'] = '/usr/bin/python scriptserver.py %s' % zoneid
        zonescriptserver = _add_process(s, processgroup, zoneid+"-scriptserver", settings, 1)

        if addtogroup: