Ticket #5419: 0001-Switch-from-Paste-for-serving-to-Waitress.patch

File 0001-Switch-from-Paste-for-serving-to-Waitress.patch, 7.1 KB (added by Christopher Allan Webber, 8 years ago)

Replace Paste(/Gunicorn) code with Waitress

  • lazystarter.sh

    From bb074d7b63884bccfef050040b2ca6c113c1a683 Mon Sep 17 00:00:00 2001
    From: Christopher Allan Webber <cwebber@dustycloud.org>
    Date: Wed, 17 Feb 2016 17:39:32 -0800
    Subject: [PATCH] Switch from Paste for serving to Waitress
    
    Incredibly, it looks like none of our documentation has to change taking
    this route...!
    ---
     lazystarter.sh                    | 44 +++++----------------------------------
     mediagoblin/app.py                | 31 ---------------------------
     mediagoblin/gmg_commands/serve.py |  1 -
     mediagoblin/tests/test_paste.ini  |  2 +-
     paste.ini                         | 19 +++++++++--------
     setup.py                          |  6 +-----
     6 files changed, 17 insertions(+), 86 deletions(-)
    
    diff --git a/lazystarter.sh b/lazystarter.sh
    index 9836279..0ed22fd 100755
    a b  
    1919selfname=$(basename "$0")
    2020local_bin="./bin"
    2121
    22 # Test whether or not gunicorn is installed
    23 # -----------------------------------------
    24 if [ -f "${local_bin}/python" ]; then
    25     our_python="${local_bin}/python";
    26 else
    27     our_python="python";
    28 fi
    29 
    30 if $our_python -c "import sys
    31 try:
    32     import gunicorn
    33     sys.exit(0)
    34 except ImportError:
    35     sys.exit(1)
    36 "; then
    37     use_gunicorn=true;
    38 else
    39     use_gunicorn=false;
    40 fi
    41 # -----------------------------------------
    42 
    4322case "$selfname" in
    4423    lazyserver.sh)
    45         if $use_gunicorn; then
    46             starter_cmd=gunicorn;
    47         else
    48             starter_cmd=paster;
    49         fi
     24        starter_cmd=paster;
    5025        ini_prefix=paste
    5126        ;;
    5227    lazycelery.sh)
    esac  
    6237if [ "$1" = "-h" ]; then
    6338    echo "$0 [-h] [-c filename.ini] [ARGS_to_${starter_cmd} ...]"
    6439    echo ""
    65     if $use_gunicorn; then
    66         echo "   For Gunicorn settings, see at:"
    67         echo "      http://docs.gunicorn.org/en/19.0/settings.html"
    68     else
    69         echo "   For example:"
    70         echo "         $0 -c fcgi.ini port_number=23371"
    71         echo "     or: $0 --server-name=fcgi --log-file=paste.log"
    72     fi
     40    echo "   For example:"
     41    echo "         $0 -c fcgi.ini port_number=23371"
     42    echo "     or: $0 --server-name=fcgi --log-file=paste.log"
    7343    echo ""
    7444    echo "   The configfile defaults to ${ini_prefix}_local.ini,"
    7545    echo "   if that is readable, otherwise ${ini_prefix}.ini."
    set -x  
    11282export CELERY_ALWAYS_EAGER=true
    11383case "$selfname" in
    11484    lazyserver.sh)
    115         if $use_gunicorn; then
    116             $starter --paste "$ini_file" --log-file=- $@;
    117         else
    118             $starter serve "$ini_file" "$@" --reload;
    119         fi
     85        $starter serve "$ini_file" "$@" --reload;
    12086        ;;
    12187    lazycelery.sh)
    12288        MEDIAGOBLIN_CONFIG="${ini_file}" \
  • mediagoblin/app.py

    diff --git a/mediagoblin/app.py b/mediagoblin/app.py
    index b984696..345aa04 100644
    a b def paste_app_factory(global_config, **app_config):  
    365365    mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app)
    366366
    367367    return mgoblin_app
    368 
    369 
    370 def paste_server_selector(wsgi_app, global_config=None, **app_config):
    371     """
    372     Select between gunicorn and paste depending on what ia available
    373     """
    374     # See if we can import the gunicorn server...
    375     # otherwise we'll use the paste server
    376     try:
    377         import gunicorn
    378     except ImportError:
    379         gunicorn = None
    380 
    381     if gunicorn is None:
    382         # use paste
    383         from paste.httpserver import server_runner
    384 
    385         cleaned_app_config = dict(
    386             [(key, app_config[key])
    387              for key in app_config
    388              if key in ["host", "port", "handler", "ssl_pem", "ssl_context",
    389                         "server_version", "protocol_version", "start_loop",
    390                         "daemon_threads", "socket_timeout", "use_threadpool",
    391                         "threadpool_workers", "threadpool_options",
    392                         "request_queue_size"]])
    393 
    394         return server_runner(wsgi_app, global_config, **cleaned_app_config)
    395     else:
    396         # use gunicorn
    397         from gunicorn.app.pasterapp import PasterServerApplication
    398         return PasterServerApplication(wsgi_app, global_config, **app_config)
  • mediagoblin/gmg_commands/serve.py

    diff --git a/mediagoblin/gmg_commands/serve.py b/mediagoblin/gmg_commands/serve.py
    index 64400fd..6ded1cf 100644
    a b class ServeCommand(object):  
    2929        return loadapp(app_spec, name=name, relative_to=relative_to, **kwargs)
    3030
    3131    def daemonize(self):
    32         # TODO: pass to gunicorn if available
    3332        pass
    3433
    3534    def restart_with_reloader(self):
  • mediagoblin/tests/test_paste.ini

    diff --git a/mediagoblin/tests/test_paste.ini b/mediagoblin/tests/test_paste.ini
    index 8d75c3c..1c5f09f 100644
    a b config = %(here)s/mediagoblin.ini  
    1313CELERY_ALWAYS_EAGER = true
    1414
    1515[server:main]
    16 use = egg:gunicorn
     16use = egg:waitress#main
    1717host = 127.0.0.1
    1818port = 6543
  • paste.ini

    diff --git a/paste.ini b/paste.ini
    index 68fd9de..ce3f01e 100644
    a b  
    66debug = false
    77
    88[pipeline:main]
    9 pipeline = errors mediagoblin
     9# pipeline = errors mediagoblin
     10pipeline = mediagoblin
    1011
    1112[app:mediagoblin]
    1213use = egg:mediagoblin#app
    debug = false  
    5152# The server that is run by default.
    5253# By default, should only be accessable locally
    5354[server:main]
    54 use = egg:mediagoblin#paste_server_selector
     55use = egg:waitress#main
    5556host = 127.0.0.1
    5657port = 6543
    57 # Gunicorn settings. See http://docs.gunicorn.org/en/19.0/settings.html
    58 # for more information about configuring Gunicorn
    59 proc_name = gmg
    60 reload = true
    61 accesslog = -
     58# # Gunicorn settings. See http://docs.gunicorn.org/en/19.0/settings.html
     59# # for more information about configuring Gunicorn
     60# proc_name = gmg
     61# reload = true
     62# accesslog = -
    6263
    6364#######################
    6465# Helper server configs
    accesslog = -  
    6970# Use this if you want to run on port 6543 and have MediaGoblin be
    7071# viewable externally
    7172[server:broadcast]
    72 use = egg:Paste#http
     73use = egg:waitress#main
    7374host = 0.0.0.0
    7475port = 6543
    7576
    host = %(fcgi_host)s  
    8081port = %(fcgi_port)s
    8182
    8283[server:http]
    83 use = egg:Paste#http
     84use = egg:waitress#main
    8485host = %(http_host)s
    8586port = %(http_port)s
  • setup.py

    diff --git a/setup.py b/setup.py
    index 96325ff..e71f3af 100644
    a b def get_version():  
    4343pyversion_install_requires = []
    4444if PY2:
    4545    pyversion_install_requires.append('argparse')  # only for < 2.7
    46     pyversion_install_requires.append('PasteScript')
    4746    # newer sqlalchemy-migrate requires pbr which BREAKS EVERYTHING AND IS
    4847    # TERRIBLE AND IS THE END OF ALL THINGS
    4948    # I'd love to remove this restriction.
    if PY2:  
    5554    pyversion_install_requires.append('mock==1.0.1')  # mock is in the stdlib for 3.3+
    5655    # PyPI version (1.4.2) does not have proper Python 3 support
    5756    pyversion_install_requires.append('ExifRead')
    58     pyversion_install_requires.append('PasteScript')
    59     pyversion_install_requires.append('Paste')
    60 else:
    61     pyversion_install_requires.append('gunicorn')
    6257
    6358install_requires = [
     59    'waitress',
    6460    'alembic==0.6.6',
    6561    'python-dateutil',
    6662    'wtforms',