[openstack-dev] mod_wsgi: what services are people using with it?

Nick Papadonis npapadonis at gmail.com
Fri Aug 19 18:46:06 UTC 2016


Here's an example with SSL enabled:

mod_wsgi:
#!/usr/bin/python2.7
import os
import sys

from oslo_utils import encodeutils

# XXX reduce dependencies
from glance.cmd.api import main
import glance_store
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
import osprofiler.notifier
import osprofiler.web

import threading

from glance.common import config
from glance.common import exception
from glance.common import wsgi
from glance import notifier

CONF = cfg.CONF
CONF.import_group("profiler", "glance.common.wsgi")
logging.register_options(CONF)

def fail(e):
    global KNOWN_EXCEPTIONS
    return_code = KNOWN_EXCEPTIONS.index(type(e)) + 1
    sys.stderr.write("ERROR: %s\n" % encodeutils.exception_to_unicode(e))
    sys.exit(return_code)

if __name__ == "__main__":
    sys.exit(main())
else:
    KNOWN_EXCEPTIONS = (RuntimeError,
                        exception.WorkerCreationFailure,
                        glance_store.exceptions.BadStoreConfiguration)

    try:
        config_files = cfg.find_config_files(project='glance',
prog='glance-api')
        config.parse_args(default_config_files=config_files)
        config.set_config_defaults()
        logging.setup(CONF, 'glance') # XXX
        notifier.set_defaults()
       """Initialize glance store."""
        glance_store.register_opts(CONF)
        glance_store.create_stores(CONF)
        glance_store.verify_default_store()

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "glance", "api",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
            osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
        else:
            osprofiler.web.disable()

        application = None
        app_lock = threading.Lock()

        with app_lock:
            if application is None:
                application = config.load_paste_app('glance-api')
    except KNOWN_EXCEPTIONS as e:
        fail(e)

-----
import os
from subprocess import CalledProcessError, check_call, Popen
import sys

def httpd(cmd):
    cmd = ['/usr/apache2/2.4/bin/httpd', '-f',
           '/var/lib/glance/api-httpd.conf',
           '-k', cmd]
    try:
        Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
    except CalledProcessError as err:
        print >> sys.stderr, 'Error executing %s: %s' % (cmd, err)
        sys.exit(1)

    sys.exit(0)

def start():
    httpd('start')

def stop():
    httpd('stop')

def restart():
    httpd('restart')

----

ServerRoot "/usr/apache2/2.4"

LoadModule authn_file_module libexec/mod_authn_file.so
LoadModule authn_core_module libexec/mod_authn_core.so
LoadModule authz_host_module libexec/mod_authz_host.so
LoadModule authz_groupfile_module libexec/mod_authz_groupfile.so
LoadModule authz_user_module libexec/mod_authz_user.so
LoadModule authz_core_module libexec/mod_authz_core.so
LoadModule access_compat_module libexec/mod_access_compat.so
LoadModule auth_basic_module libexec/mod_auth_basic.so
LoadModule reqtimeout_module libexec/mod_reqtimeout.so
LoadModule filter_module libexec/mod_filter.so
LoadModule log_config_module libexec/mod_log_config.so
LoadModule env_module libexec/mod_env.so
LoadModule headers_module libexec/mod_headers.so
LoadModule version_module libexec/mod_version.so
LoadModule slotmem_shm_module libexec/mod_slotmem_shm.so
<IfDefine prefork>
    LoadModule mpm_prefork_module libexec/mod_mpm_prefork.so
</IfDefine>
<IfDefine worker>
    LoadModule mpm_worker_module libexec/mod_mpm_worker.so
</IfDefine>
<IfDefine !prefork>
    <IfDefine !worker>
        LoadModule mpm_event_module libexec/mod_mpm_event.so
    </IfDefine>
</IfDefine>
LoadModule unixd_module libexec/mod_unixd.so
LoadModule status_module libexec/mod_status.so
LoadModule alias_module libexec/mod_alias.so
LoadModule wsgi_module libexec/mod_wsgi-2.7.so

LoadModule ssl_module libexec/mod_ssl.so

<IfModule unixd_module>
    User glance
    Group glance
</IfModule>

PidFile /var/lib/glance/glance-api.httpd.pid

ServerName XXX

Listen 9292

ErrorLogFormat "%{cu}t %M"
ErrorLog "/var/log/glance/glance-api_error.log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %u %t \"%r\" %p %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"" combined
</IfModule>

CustomLog /var/log/glance/glance-api_access.log combined

# Limit request up to 5GB
<Directory /usr/lib/python2.7/vendor-packages/glance/common>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
    LimitRequestBody 5368709122
</Directory>

WSGISocketPrefix /var/run/glance-api_wsgi_

# Enable Chunks Requests Glance requires it
<VirtualHost *:9292>

    SSLEngine On

    # Disable the known insecure SSLv3 protocol
    SSLProtocol all -SSLv3

    SSLCertificateFile /etc/glance/ssl/public/server-cert-fchain.pem
    SSLCACertificateFile /etc/certs/ca-certificates.crt
    SSLCertificateKeyFile /etc/glance/ssl/private/server-key.pem

    WSGIChunkedRequest On
    WSGIDaemonProcess glance-api processes=2 threads=1 user=glance
group=glance display-name=%{GROUP}
    WSGIProcessGroup glance-api
    WSGIScriptAlias / /usr/lib/glance/glance-api
    WSGIApplicationGroup %{GLOBAL}
    #WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
</VirtualHost>

On Thu, Aug 18, 2016 at 2:07 PM, Matthew Thode <prometheanfire at gentoo.org>
wrote:

> On 08/17/2016 03:52 PM, Nick Papadonis wrote:
> > Comments
> >
> >
> > Glance worked for me in Mitaka.  I had to specify 'chunked transfers'
> > and increase the size limit to 5GB.  I had to pull some of the WSGI
> > source from glance and alter it slightly to call from Apache.
> >
> > I saw that Nova claims mod_wsgi is 'experimental'.  Interested in it's
> > really experimental or folks use it in production.
> >
> > Nick
>
> I haven't found any docs on getting mod_wsgi working for glance do you
> happen to have a link?
>
> --
> -- Matthew Thode (prometheanfire)
>
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20160819/3e54f472/attachment.html>


More information about the OpenStack-dev mailing list