コード例 #1
0
def setup_server():
    global setup_state

    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)

    if not settings.conf.mongodb_uri:
        setup_state = 'setup'
    elif check_db_ver(db_ver_int):
        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(0.5)

    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')
コード例 #2
0
ファイル: server.py プロジェクト: xyz12810/pritunl
def setup_server():
    global setup_state

    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)

    if not settings.conf.mongodb_uri:
        setup_state = 'setup'
    elif check_db_ver(db_ver_int):
        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)

    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')