Add deploying karbor-api with mod-wsgi

This patch adds support to run karbor-api with mod-wsgi.
It provides wsgi app script files and an example Apache2
configuration file for using karbor API through mod_wsgi.

Closes-Bug: #1681500
Change-Id: I292894f59809b84dc1697767a5d3d59861faac84
This commit is contained in:
chenying 2017-04-05 23:15:36 +08:00
parent 699365c8b4
commit ecdfd06ce7
4 changed files with 133 additions and 0 deletions

49
doc/source/mod_wsgi.rst Normal file
View File

@ -0,0 +1,49 @@
..
Except where otherwise noted, this document is licensed under Creative
Commons Attribution 3.0 License. You can view the license at:
https://creativecommons.org/licenses/by/3.0/
Installing Karbor API with mod_wsgi
=====================================
#. Install the Apache Service::
Fedora 21/RHEL7/CentOS7:
sudo yum install httpd
Fedora 22 (or higher):
sudo dnf install httpd
Debian/Ubuntu:
apt-get install apache2
#. Copy ``etc/apache2/apache-karbor-api.conf`` under the apache sites::
Fedora/RHEL7/CentOS7:
sudo cp etc/apache2/apache-karbor-api.conf /etc/httpd/conf.d/apache-karbor-api.conf
Debian/Ubuntu:
sudo cp etc/apache2/apache-karbor-api.conf /etc/apache2/sites-available/apache-karbor-api.conf
#. Edit ``apache-karbor-api.conf`` according to installtion
and environment.
* Modify the ``WSGIDaemonProcess`` directive to set the ``user`` and
``group`` values to appropriate user on your server.
* Modify the ``WSGIScriptAlias`` directive to point to the
watcher/api/app.wsgi script.
* Modify the ``Directory`` directive to set the path to the Watcher API
code.
* Modify the ``ErrorLog and CustomLog`` to redirect the logs to the right
directory.
#. Enable the apache watcher site and reload::
Fedora/RHEL7/CentOS7:
sudo systemctl reload httpd
Debian/Ubuntu:
sudo a2ensite apache-karbor-api
sudo apache2ctl -k restart

View File

@ -0,0 +1,37 @@
# 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.
# This is an example Apache2 configuration file for using
# karbor API through mod_wsgi
Listen 8799
<VirtualHost *:8799>
WSGIDaemonProcess osapi_karbor user=stack group=stack processes=2 threads=2 display-name=%{GROUP}
WSGIProcessGroup osapi_karbor
WSGIScriptAlias / /usr/local/bin/karbor-wsgi
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
SetEnv APACHE_RUN_USER stack
SetEnv APACHE_RUN_GROUP stack
ErrorLogFormat "%M"
ErrorLog /var/log/apache2/karbor_api.log
CustomLog /var/log/apache2/karbor_api_access.log combined
<Directory /usr/local/bin>
Require all granted
</Directory>
</VirtualHost>

45
karbor/wsgi/wsgi.py Normal file
View File

@ -0,0 +1,45 @@
# 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.
"""Cinder OS API WSGI application."""
import sys
import warnings
from karbor import objects
warnings.simplefilter('once', DeprecationWarning)
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import wsgi
from karbor import i18n
i18n.enable_lazy()
# Need to register global_opts
from karbor.common import config # noqa
from karbor import rpc
from karbor import version
CONF = cfg.CONF
def initialize_application():
objects.register_all()
CONF(sys.argv[1:], project='karbor',
version=version.version_string())
logging.setup(CONF, "karbor")
rpc.init(CONF)
return wsgi.Loader(CONF).load_app(name='osapi_karbor')

View File

@ -35,6 +35,8 @@ console_scripts =
karbor-manage = karbor.cmd.manage:main
karbor-operationengine = karbor.cmd.operationengine:main
karbor-protection = karbor.cmd.protection:main
wsgi_scripts =
karbor-wsgi = karbor.wsgi.wsgi:initialize_application
karbor.database.migration_backend =
sqlalchemy = oslo_db.sqlalchemy.migration
karbor.protections =