示例#1
0
文件: server.py 项目: Flux159/pritunl
def server_thread():
    global server

    app.logger.setLevel(logging.DEBUG)
    app.logger.addFilter(logger.log_filter)
    app.logger.addHandler(logger.log_handler)

    server_port = upgrade.get_server_port()
    server = wsgiserver.CherryPyWSGIServer(
        (settings.conf.bind_addr, server_port), app,
        server_name=wsgiserver.CherryPyWSGIServer.version,
        timeout=1,
        shutdown_timeout=0.5,
    )

    if settings.conf.ssl:
        server_cert_path, server_chain_path, server_key_path, \
            server_dh_path = upgrade.setup_cert()

        server.ssl_adapter = SSLAdapter(
            server_cert_path,
            server_key_path,
            server_chain_path,
            server_dh_path,
        )

    try:
        server.start()
    except StopServer:
        pass

    time.sleep(1.5)
    setup_ready.set()
    settings.local.server_start.set()
示例#2
0
def server_thread():
    global server

    app.logger.setLevel(logging.DEBUG)
    app.logger.addFilter(logger.log_filter)
    app.logger.addHandler(logger.log_handler)

    server_port = upgrade.get_server_port(bool(settings.conf.mongodb_uri))
    server = wsgiserver.CherryPyWSGIServer(
        (settings.conf.bind_addr, server_port), app,
        server_name=wsgiserver.CherryPyWSGIServer.version,
        timeout=1,
        shutdown_timeout=0.5,
    )

    server_cert_path = os.path.join(settings.conf.temp_path,
        SETUP_SERVER_CERT_NAME)
    server_key_path = os.path.join(settings.conf.temp_path,
        SETUP_SERVER_KEY_NAME)

    if settings.conf.ssl:
        upgrade.setup_cert(
            bool(settings.conf.mongodb_uri),
            server_cert_path,
            server_key_path,
        )
        server.ssl_adapter = SSLAdapter(server_cert_path, server_key_path)

    try:
        server.start()
    except StopServer:
        pass

    setup_ready.set()
    settings.local.server_start.set()
示例#3
0
def server_thread():
    global server

    app.logger.setLevel(logging.DEBUG)
    app.logger.addFilter(logger.log_filter)
    app.logger.addHandler(logger.log_handler)

    server_port = upgrade.get_server_port()
    server = wsgiserver.CherryPyWSGIServer(
        (settings.conf.bind_addr, server_port),
        app,
        server_name=wsgiserver.CherryPyWSGIServer.version,
        timeout=1,
        shutdown_timeout=0.5,
    )

    if settings.conf.ssl:
        server_cert_path, server_chain_path, server_key_path, \
            server_dh_path = upgrade.setup_cert()

        server.ssl_adapter = SSLAdapter(
            server_cert_path,
            server_key_path,
            server_chain_path,
            server_dh_path,
        )

    try:
        server.start()
    except StopServer:
        pass

    setup_ready.set()
    settings.local.server_start.set()
示例#4
0
def server_thread():
    global server
    global web_process
    global web_process_state

    app.logger.setLevel(logging.DEBUG)
    app.logger.addFilter(logger.log_filter)
    app.logger.addHandler(logger.log_handler)

    server = cheroot.wsgi.Server(
        ('localhost', settings.conf.internal_port),
        app,
        shutdown_timeout=0.5,
    )
    server.server_name = ''

    if settings.conf.ssl:
        server_cert_path, server_key_path = upgrade.setup_cert()
    else:
        server_cert_path = None
        server_key_path = None

    web_process_state = True
    web_process = subprocess.Popen(
        ['pritunl-web'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        env=dict(os.environ, **{
            'REVERSE_PROXY_HEADER': '',
            'REDIRECT_SERVER': 'true',
            'BIND_HOST': settings.conf.bind_addr,
            'BIND_PORT': str(upgrade.get_server_port()),
            'INTERNAL_ADDRESS': 'localhost:%s' % settings.conf.internal_port,
            'CERT_PATH': server_cert_path or '',
            'KEY_PATH': server_key_path or '',
        }),
    )

    def poll_thread():
        time.sleep(0.5)
        if web_process.wait() and web_process_state:
            time.sleep(0.25)
            if not check_global_interrupt():
                stdout, stderr = web_process._communicate(None)
                logger.error(
                    'Setup web server process exited unexpectedly', 'setup',
                    stdout=stdout,
                    stderr=stderr,
                )
            set_global_interrupt()
        else:
            server.interrupt = ServerStop('Stop server')
    thread = threading.Thread(target=poll_thread)
    thread.daemon = True
    thread.start()

    try:
        server.start()
    except ServerStop:
        pass

    setup_ready.set()
    settings.local.server_start.set()
示例#5
0
文件: server.py 项目: ijat/pritunl
def server_thread():
    global server
    global web_process
    global web_process_state

    app.logger.setLevel(logging.DEBUG)
    app.logger.addFilter(logger.log_filter)
    app.logger.addHandler(logger.log_handler)

    server = wsgiserver.CherryPyWSGIServer(
        ('localhost', settings.conf.internal_port), app,
        shutdown_timeout=0.5,
    )
    server.server_name = ''

    if settings.conf.ssl:
        server_cert_path, server_key_path = upgrade.setup_cert()
    else:
        server_cert_path = None
        server_key_path = None

    web_process_state = True
    web_process = subprocess.Popen(
        ['pritunl-web'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        env=dict(os.environ, **{
            'REVERSE_PROXY_HEADER': '',
            'REDIRECT_SERVER': 'true',
            'BIND_HOST': settings.conf.bind_addr,
            'BIND_PORT': str(upgrade.get_server_port()),
            'INTERNAL_ADDRESS': 'localhost:%s' % settings.conf.internal_port,
            'CERT_PATH': server_cert_path or '',
            'KEY_PATH': server_key_path or '',
        }),
    )

    def poll_thread():
        time.sleep(0.5)
        if web_process.wait() and web_process_state:
            time.sleep(0.25)
            if not check_global_interrupt():
                stdout, stderr = web_process._communicate(None)
                logger.error(
                    'Setup web server process exited unexpectedly', 'setup',
                    stdout=stdout,
                    stderr=stderr,
                )
            set_global_interrupt()
        else:
            server.interrupt = ServerStop('Stop server')
    thread = threading.Thread(target=poll_thread)
    thread.daemon = True
    thread.start()

    try:
        server.start()
    except ServerStop:
        pass

    setup_ready.set()
    settings.local.server_start.set()