Beispiel #1
0
def setup_server():
    global setup_state

    last_error = time.time() - 24
    while True:
        try:
            utils.get_db_ver_int()
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if not settings.conf.mongodb_uri:
        setup_state = 'setup'
    elif check_db_ver():
        setup_state = 'upgrade'

    if setup_state:
        logger.info('Starting setup server', 'setup')

        if setup_state == 'upgrade':
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()
        time.sleep(1.5)

    upgrade.database_clean_up()

    last_error = time.time() - 24
    while True:
        try:
            utils.set_db_ver(__version__, MIN_DATABASE_VER)
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')
Beispiel #2
0
def setup_server():
    global setup_state

    last_error = time.time() - 24
    while True:
        try:
            utils.get_db_ver_int()
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if not settings.conf.mongodb_uri:
        setup_state = 'setup'
    elif check_db_ver():
        setup_state = 'upgrade'

    if setup_state:
        logger.info('Starting setup server', 'setup')

        if setup_state == 'upgrade':
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()
        time.sleep(1.5)

    upgrade.database_clean_up()

    last_error = time.time() - 24
    while True:
        try:
            utils.set_db_ver(__version__, MIN_DATABASE_VER)
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')
Beispiel #3
0
def upgrade_server():
    if utils.get_db_ver_int() < 10000000000004000:
        logger.info('Running 0.10.x database upgrade', 'upgrade')
        upgrade_0_10_x()
        utils.set_db_ver('1.0.0')
    else:
        logger.info('DB version changed, no upgrade needed', 'upgrade')
Beispiel #4
0
def setup_server():
    db_ver_int = utils.get_db_ver_int()

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error('Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    utils.set_db_ver(__version__)
Beispiel #5
0
def upgrade_server():
    if utils.get_db_ver_int() < utils.get_int_ver('1.4.0.0'):
        logger.info('Running 1.4 database upgrade', 'upgrade')
        upgrade_1_4()
        utils.set_db_ver('1.4.0.0')
    else:
        logger.info('No upgrade needed', 'upgrade')
Beispiel #6
0
def upgrade_server():
    upgraded = False

    if utils.get_db_ver_int() < utils.get_int_ver('1.4.0.0'):
        upgraded = True
        logger.info('Running 1.4 database upgrade', 'upgrade')
        upgrade_1_4()
        utils.set_db_ver('1.4.0.0')

    if utils.get_db_ver_int() < utils.get_int_ver('1.5.0.0'):
        upgraded = True
        logger.info('Running 1.5 database upgrade', 'upgrade')
        upgrade_1_5()
        utils.set_db_ver('1.5.0.0')

    if not upgraded:
        logger.info('No upgrade needed', 'upgrade')
Beispiel #7
0
def setup_server():
    last_error = time.time() - 24
    while True:
        try:
            db_ver_int = utils.get_db_ver_int()
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error('Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade.database_setup()
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    upgrade.database_clean_up()

    last_error = time.time() - 24
    while True:
        try:
            utils.set_db_ver(__version__)
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')
Beispiel #8
0
def setup_mongodb_put():
    global setup_state

    setup_key = flask.request.json['setup_key']
    mongodb_uri = flask.request.json['mongodb_uri']

    if setup_state != 'setup':
        return flask.abort(404)

    utils.rand_sleep()
    if setup_key != settings.local.setup_key:
        return utils.jsonify(
            {
                'error': SETUP_KEY_INVALID,
                'error_msg': SETUP_KEY_INVALID_MSG,
            }, 400)

    if not mongodb_uri:
        return utils.jsonify(
            {
                'error': MONGODB_URI_INVALID,
                'error_msg': MONGODB_URI_INVALID_MSG,
            }, 400)

    try:
        client = pymongo.MongoClient(mongodb_uri,
                                     connectTimeoutMS=MONGO_CONNECT_TIMEOUT)
        database = client.get_default_database()
    except pymongo.errors.ConfigurationError as error:
        if 'auth failed' in str(error):
            return utils.jsonify(
                {
                    'error': MONGODB_AUTH_ERROR,
                    'error_msg': MONGODB_AUTH_ERROR_MSG,
                }, 400)
        raise
    except pymongo.errors.ConnectionFailure:
        return utils.jsonify(
            {
                'error': MONGODB_CONNECT_ERROR,
                'error_msg': MONGODB_CONNECT_ERROR_MSG,
            }, 400)

    settings.conf.mongodb_uri = mongodb_uri
    settings.conf.commit()

    db_ver_int = utils.get_db_ver_int()
    if check_db_ver(db_ver_int):
        setup_state = 'upgrade'
        upgrade_database()
    else:
        stop_server()

    return ''
Beispiel #9
0
def setup_server():
    last_error = time.time() - 24
    while True:
        try:
            db_ver_int = utils.get_db_ver_int()
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error(
            'Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    last_error = time.time() - 24
    while True:
        try:
            utils.set_db_ver(__version__)
            break
        except:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')
Beispiel #10
0
def setup_mongodb_put():
    global setup_state

    setup_key = flask.request.json['setup_key']
    mongodb_uri = flask.request.json['mongodb_uri']

    if setup_state != 'setup':
        return flask.abort(404)

    utils.rand_sleep()
    if setup_key != settings.local.setup_key:
        return utils.jsonify({
            'error': SETUP_KEY_INVALID,
            'error_msg': SETUP_KEY_INVALID_MSG,
        }, 400)

    if not mongodb_uri:
        return utils.jsonify({
            'error': MONGODB_URI_INVALID,
            'error_msg': MONGODB_URI_INVALID_MSG,
        }, 400)

    try:
        client = pymongo.MongoClient(mongodb_uri,
            connectTimeoutMS=MONGO_CONNECT_TIMEOUT)
        database = client.get_default_database()
    except pymongo.errors.ConfigurationError as error:
        if 'auth failed' in str(error):
            return utils.jsonify({
                'error': MONGODB_AUTH_ERROR,
                'error_msg': MONGODB_AUTH_ERROR_MSG,
            }, 400)
        raise
    except pymongo.errors.ConnectionFailure:
        return utils.jsonify({
            'error': MONGODB_CONNECT_ERROR,
            'error_msg': MONGODB_CONNECT_ERROR_MSG,
        }, 400)

    settings.conf.mongodb_uri = mongodb_uri
    settings.conf.commit()

    db_ver_int = utils.get_db_ver_int()
    if check_db_ver(db_ver_int):
        setup_state = 'upgrade'
        upgrade_database()
    else:
        stop_server()

    return ''
Beispiel #11
0
def setup_server():
    last_error = time.time() - 24
    while True:
        try:
            db_ver_int = utils.get_db_ver_int()
            break
        except pymongo.errors.ConnectionFailure:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error(
            'Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    # Fix for replaced conf file in 0.10.x upgrade
    if db_ver_int < 10000000000004000 and not settings.conf.mongodb_uri:
        settings.conf.mongodb_uri = 'mongodb://localhost:27017/pritunl'
        settings.conf.commit()

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    utils.set_db_ver(__version__)
Beispiel #12
0
def setup_server():
    last_error = time.time() - 24
    while True:
        try:
            db_ver_int = utils.get_db_ver_int()
            break
        except pymongo.errors.ConnectionFailure:
            time.sleep(0.5)
            if time.time() - last_error > 30:
                last_error = time.time()
                logger.exception('Error connecting to mongodb server')

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error('Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    # Fix for replaced conf file in 0.10.x upgrade
    if db_ver_int < 10000000000004000 and not settings.conf.mongodb_uri:
        settings.conf.mongodb_uri = 'mongodb://localhost:27017/pritunl'
        settings.conf.commit()

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    utils.set_db_ver(__version__)
Beispiel #13
0
def setup_server():
    db_ver_int = utils.get_db_ver_int()

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error(
            'Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    # Fix for replaced conf file in 0.10.x upgrade
    if db_ver_int < 10000000000004000 and not settings.conf.mongodb_uri:
        settings.conf.mongodb_uri = 'mongodb://localhost:27017/pritunl'
        settings.conf.commit()

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    utils.set_db_ver(__version__)
Beispiel #14
0
def setup_server():
    db_ver_int = utils.get_db_ver_int()

    listener.add_listener('system', on_system_msg)

    if db_ver_int > settings.local.version_int:
        logger.error('Database version is newer than server version',
            'setup',
            db_version=db_ver_int,
            server_version=settings.local.version_int,
        )
        exit(75)

    # Fix for replaced conf file in 0.10.x upgrade
    if db_ver_int < 100000000 and not settings.conf.mongodb_uri:
        settings.conf.mongodb_uri = 'mongodb://localhost:27017/pritunl'
        settings.conf.commit()

    global db_setup
    db_setup = not settings.conf.mongodb_uri

    global server_upgrade
    server_upgrade = db_ver_int and db_ver_int < settings.local.version_int

    if db_setup or server_upgrade:
        logger.info('Starting setup server', 'setup')

        if not db_setup:
            upgrade_database()

        settings.local.server_start.clear()

        thread = threading.Thread(target=server_thread)
        thread.daemon = True
        thread.start()

        setup_ready.wait()

    utils.set_db_ver(__version__)
Beispiel #15
0
def upgrade_server():
    if utils.get_db_ver_int() < 100000000:
        logger.info('Running 0.10.x database upgrade', 'upgrade')
        upgrade_0_10_x()
        utils.set_db_ver('1.0.0')
Beispiel #16
0
def upgrade_server():
    if utils.get_db_ver_int() < 100000000:
        logger.info('Running 0.10.x database upgrade', 'upgrade')
        upgrade_0_10_x()
        utils.set_db_ver('1.0.0')