Esempio n. 1
0
def main():  # pragma: no cover
    """Run server from the command line."""
    import multiprocessing

    from docopt import docopt
    from gunicorn.app.pasterapp import PasterServerApplication

    arguments = docopt(__doc__, version="pydap %s" % __version__)

    # init templates?
    if arguments["--init"]:
        init(arguments["--init"])
        return

    # create pydap app
    data, templates = arguments["--data"], arguments["--templates"]
    app = DapServer(data, templates)

    # configure app so that is reads static assets from the template directory
    # or from the package
    if templates and os.path.exists(os.path.join(templates, "static")):
        static = os.path.join(templates, "static")
    else:
        static = ("pydap.wsgi", "templates/static")
    app = StaticMiddleware(app, static)

    # configure WSGI server
    workers = multiprocessing.cpu_count() * 2 + 1
    PasterServerApplication(
        app,
        host=arguments["--bind"],
        port=int(arguments["--port"]),
        workers=workers,
        worker_class=arguments["--worker-class"]).run()
Esempio n. 2
0
def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
    """\
    A paster server.

    Then entry point in your paster ini file should looks like this:

    [server:main]
    use = egg:gunicorn#main
    host = 127.0.0.1
    port = 5000

    """

    util.warn("""This command is deprecated.

    You should now use the `--paste` option. Ex.:

        gunicorn --paste development.ini
    """)

    from gunicorn.app.pasterapp import PasterServerApplication
    PasterServerApplication(app,
                            gcfg=gcfg,
                            host=host,
                            port=port,
                            *args,
                            **kwargs).run()
Esempio n. 3
0
def paste_server_selector(wsgi_app, global_config=None, **app_config):
    """
    Select between gunicorn and paste depending on what ia available
    """
    # See if we can import the gunicorn server...
    # otherwise we'll use the paste server
    try:
        import gunicorn
    except ImportError:
        gunicorn = None

    if gunicorn is None:
        # use paste
        from paste.httpserver import server_runner

        cleaned_app_config = dict([
            (key, app_config[key]) for key in app_config if key in [
                "host", "port", "handler", "ssl_pem", "ssl_context",
                "server_version", "protocol_version", "start_loop",
                "daemon_threads", "socket_timeout", "use_threadpool",
                "threadpool_workers", "threadpool_options",
                "request_queue_size"
            ]
        ])

        return server_runner(wsgi_app, global_config, **cleaned_app_config)
    else:
        # use gunicorn
        from gunicorn.app.pasterapp import PasterServerApplication
        return PasterServerApplication(wsgi_app, global_config, **app_config)
Esempio n. 4
0
def server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
    # Workaround for gunicorn #540
    # Remove after updating gunicorn > 17.5
    from gunicorn.config import get_default_config_file
    from gunicorn.app.pasterapp import PasterServerApplication

    cfgfname = kwargs.pop('config', get_default_config_file())

    paste_server = PasterServerApplication(
        app,
        gcfg=gcfg,
        host=host,
        port=port,
        *args,
        **kwargs
    )

    if cfgfname:
        paste_server.load_config_from_file(cfgfname)

    paste_server.run()
Esempio n. 5
0
def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
    """\
    A paster server.
    
    Then entry point in your paster ini file should looks like this:
    
    [server:main]
    use = egg:gunicorn#main
    host = 127.0.0.1
    port = 5000
    
    """
    from gunicorn.app.pasterapp import PasterServerApplication
    PasterServerApplication(app, gcfg=gcfg, host=host, port=port, *args, **kwargs).run()
Esempio n. 6
0
def server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
    # Workaround for gunicorn #540
    # Remove after updating gunicorn > 17.5
    from gunicorn.config import get_default_config_file
    from gunicorn.app.pasterapp import PasterServerApplication

    cfgfname = kwargs.pop('config', get_default_config_file())

    paste_server = PasterServerApplication(app,
                                           gcfg=gcfg,
                                           host=host,
                                           port=port,
                                           *args,
                                           **kwargs)

    if cfgfname:
        paste_server.load_config_from_file(cfgfname)

    paste_server.run()