uwsgi improvements

This patch adds a .ini file with the configuration for running
mixmatch through uwsgi, replacing the previous `run_proxy.sh`
script which passed the configuration as arguments.

This patch also removed the wsgi configuration, making it
unsupported. The wsgi documentation has also been removed. A
follow on patch will also remove any remnants of wsgi logic.

The default port for running the proxy has been changed to
9913.

This patch also updates the `setup.cfg` file, adding the
parameters for wsgi_scripts so that pbr install the wsgi exec
on package installation.

This patch also uses apache and mod_proxy to map /resource to
the uwsgi port 9913.

Change-Id: I2069d0f28e8e14da59109158cd2912ddb284a4e3
This commit is contained in:
Kristi Nikolla 2017-06-21 13:41:04 +00:00
parent e860a37ea8
commit 10fae26c6d
12 changed files with 81 additions and 94 deletions

View File

@ -12,9 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
MIXMATCH_BIN_DIR=$(get_python_exec_prefix)
MIXMATCH_CONF_DIR="/etc/mixmatch"
MIXMATCH_UWSGI_INI="$MIXMATCH_CONF_DIR/mixmatch-uwsgi.ini"
function install_mixmatch {
pip_install $MIXMATCH_DIR
pip_install uwsgi
}
function configure_mixmatch {
@ -23,8 +27,7 @@ function configure_mixmatch {
sudo chown $STACK_USER:$STACK_USER /etc/mixmatch
cp $MIXMATCH_DIR/etc/mixmatch.conf.sample $MIXMATCH_CONF
iniset $MIXMATCH_CONF database connection "sqlite:////tmp/mixmatch.db"
iniset $MIXMATCH_CONF DEFAULT port $MIXMATCH_SERVICE_PORT
iniset $MIXMATCH_CONF database connection "sqlite://"
iniset $MIXMATCH_CONF DEFAULT service_providers default
iniset $MIXMATCH_CONF DEFAULT aggregation False
@ -51,21 +54,25 @@ function configure_mixmatch {
"$NEUTRON_SERVICE_PROTOCOL://$NEUTRON_SERVICE_HOST:$NEUTRON_SERVICE_PORT"
iniset $MIXMATCH_CONF sp_default enabled_services "image, volume, network"
run_process mixmatch "$MIXMATCH_DIR/run_proxy.sh"
# Nova
iniset $NOVA_CONF glance api_servers "$MIXMATCH_SERVICE_PROTOCOL://$HOST_IP:$MIXMATCH_SERVICE_PORT/image"
iniset $NOVA_CONF neutron url "$MIXMATCH_SERVICE_PROTOCOL://$HOST_IP:$MIXMATCH_SERVICE_PORT/network"
iniset $NOVA_CONF glance api_servers "$MIXMATCH_URL/image"
iniset $NOVA_CONF neutron url "$MIXMATCH_URL/network"
# Cinder
iniset $CINDER_CONF DEFAULT glance_api_servers \
"$MIXMATCH_SERVICE_PROTOCOL://$HOST_IP:$MIXMATCH_SERVICE_PORT/image"
iniset $CINDER_CONF DEFAULT glance_api_servers "$MIXMATCH_URL/image"
iniset $CINDER_CONF oslo_messaging_notifications driver messaging
iniset $CINDER_CONF oslo_messaging_notifications topics notifications
# Glance
iniset $GLANCE_CONF oslo_messaging_notifications driver messaging
iniset $CINDER_CONF oslo_messaging_notifications topics notifications
sudo cp $MIXMATCH_DIR/httpd/mixmatch-uwsgi.conf $(apache_site_config_for mixmatch)
enable_apache_site mixmatch
restart_apache_server
run_process mixmatch \
"$MIXMATCH_BIN_DIR/uwsgi --ini $MIXMATCH_DIR/httpd/mixmatch-uwsgi.ini"
}
function get_endpoint_ids {
@ -84,36 +91,36 @@ function register_mixmatch {
get_or_create_endpoint \
"image" \
"$REGION_NAME" \
"http://$HOST_IP:5001/image" \
"http://$HOST_IP:5001/image" \
"http://$HOST_IP:5001/image"
"$MIXMATCH_URL/image" \
"$MIXMATCH_URL/image" \
"$MIXMATCH_URL/image"
get_or_create_endpoint \
"volume" \
"$REGION_NAME" \
"http://$HOST_IP:5001/volume/v1/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v1/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v1/\$(project_id)s"
"$MIXMATCH_URL/volume/v1/\$(project_id)s" \
"$MIXMATCH_URL/volume/v1/\$(project_id)s" \
"$MIXMATCH_URL/volume/v1/\$(project_id)s"
get_or_create_endpoint \
"volumev2" \
"$REGION_NAME" \
"http://$HOST_IP:5001/volume/v2/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v2/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v2/\$(project_id)s"
"$MIXMATCH_URL/volume/v2/\$(project_id)s" \
"$MIXMATCH_URL/volume/v2/\$(project_id)s" \
"$MIXMATCH_URL/volume/v2/\$(project_id)s"
get_or_create_endpoint \
"volumev3" \
"$REGION_NAME" \
"http://$HOST_IP:5001/volume/v3/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v3/\$(project_id)s" \
"http://$HOST_IP:5001/volume/v3/\$(project_id)s"
"$MIXMATCH_URL/volume/v3/\$(project_id)s" \
"$MIXMATCH_URL/volume/v3/\$(project_id)s" \
"$MIXMATCH_URL/volume/v3/\$(project_id)s"
get_or_create_endpoint \
"network" \
"$REGION_NAME" \
"http://$HOST_IP:5001/network" \
"http://$HOST_IP:5001/network" \
"http://$HOST_IP:5001/network"
"$MIXMATCH_URL/network" \
"$MIXMATCH_URL/network" \
"$MIXMATCH_URL/network"
fi
}

View File

@ -4,7 +4,7 @@ MIXMATCH_DIR=$DEST/mixmatch
MIXMATCH_PLUGIN=$DEST/mixmatch/devstack
MIXMATCH_CONF=/etc/mixmatch/mixmatch.conf
MIXMATCH_SERVICE_PORT=${MIXMATCH_SERVICE_PORT:-5001}
MIXMATCH_SERVICE_PROTOCOL=${MIXMATCH_SERVICE_PROTOCOL:-http}
REGISTER_MIXMATCH=${REGISTER_MIXMATCH:-false}
REGISTER_MIXMATCH=${REGISTER_MIXMATCH:-false}
MIXMATCH_SERVICE_PROTOCOL=${MIXMATCH_SERVICE_PROTOCOL:-http}
MIXMATCH_URL=${MIXMATCH_URL:-"$MIXMATCH_SERVICE_PROTOCOL://$HOST_IP/resource"}

View File

@ -14,27 +14,13 @@ Install dependencies. ::
Web Server
==========
The recommended way is to run the proxy using uWSGI through the
``run_proxy.sh`` script. ::
The recommended way is to run the proxy using uwsgi and apache through the
`httpd/mixmatch-uwsgi.ini` and `httpd/mixmatch-uwsgi.conf` files respectively ::
$ ./run_proxy.sh
It is also possible to run the proxy with Apache2 and ``mod_wsgi``, but there
are limitations compared to running it with uWSGI.
- Image uploading with Glance doesn't work unless running Apache in embedded
mode.
- Image API v1 uses underscores in the header keys, which are silently dropped
by Apache. Hacking the configuration to allow these through is required.
To run the proxy with Apache in Ubuntu: ::
$ apt-get install libapache2-mod-wsgi
$ cp httpd/apache.conf /etc/apache2/sites-available/proxy.conf
$ cp etc/mixmatch.conf.sample /etc/mixmatch/mixmatch.conf
$ a2ensite proxy
$ service apache2 reload
sudo apt install uwsgi uwsgi-plugin-python libapache2-mod-proxy-uwsgi
uwsgi mixmatch/httpd/mixmatch-uwsgi.ini
sudo cp mixmatch/httpd/mixmatach-uwsgi.ini /etc/apache2/sites-available/mixmatch.conf
sudo a2ensite mixmatch
Running in a Docker Container

View File

@ -1,17 +0,0 @@
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi
Listen 5001
<VirtualHost *:5001>
WSGIPassAuthorization On
WSGIChunkedRequest On
#WSGIDaemonProcess k2k-proxy user=ubuntu group=ubuntu threads=2
WSGIScriptAlias / /home/ubuntu/k2k-proxy/httpd/k2k-proxy.wsgi
<Directory /home/ubuntu/k2k-proxy/httpd>
#WSGIProcessGroup k2k-proxy
#WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>

View File

@ -1,15 +0,0 @@
# Copyright 2016 Massachusetts Open Cloud
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mixmatch.proxy import app as application

View File

@ -0,0 +1,2 @@
KeepAlive Off
ProxyPass "/resource" "http://127.0.0.1:9913" retry=0

26
httpd/mixmatch-uwsgi.ini Normal file
View File

@ -0,0 +1,26 @@
[uwsgi]
wsgi-file = /usr/local/bin/mixmatch
http-socket = 0.0.0.0:9913
http-keepalive = false
http-chunked-input = true
# Override the default size for headers from the 4k default.
# This is required for keystone tokens.
buffer-size = 65535
# This is running standalone
master = true
enable-threads = true
# Tune this to your environment.
processes = 8
# uwsgi recommends this to prevent thundering herd on accept.
thunder-lock = true
plugins = python
# This ensures that file descriptors aren't shared between processes.
lazy-apps = true

View File

@ -17,10 +17,6 @@ from oslo_config import cfg
GROUP = None
OPTS = [
cfg.IntOpt('port',
default=5001,
help='Web Server Port'),
cfg.ListOpt('service_providers',
default=[],
help='List of service providers'),

View File

@ -19,6 +19,7 @@ cd $BASE/new/devstack
source openrc admin admin
# Register the endpoints
source $BASE/new/mixmatch/devstack/settings
source $BASE/new/mixmatch/devstack/mixmatch.sh
REGISTER_MIXMATCH=true
register_mixmatch

View File

@ -17,3 +17,7 @@ from mixmatch import session
proxy.main()
application = session.app
def get_application():
return application

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
uwsgi --socket 0.0.0.0:5001 \
--protocol=http \
--http-chunked-input \
-w mixmatch.wsgi \
--master \
--processes 8 \
--threads 1 \
2>&1

View File

@ -21,15 +21,22 @@ classifier =
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
[global]
setup_hooks =
pbr.hooks.setup_hook
[files]
packages =
mixmatch
mixmatch.config
mixmatch.extend
data_files =
etc/ = etc/*
/etc/mixmatch = etc/*
[entry_points]
wsgi_scripts =
mixmatch = mixmatch.wsgi:get_application
oslo.config.opts =
mixmatch = mixmatch.config:list_opts
mixmatch.extend =