Implement uWSGI for Magnum API

Change-Id: Iea6154c18070c82109b1d262d20c23476e4a2573
Implements: blueprint goal-deploy-api-in-wsgi
This commit is contained in:
Mohammed Naser 2018-02-12 16:41:11 -05:00
parent ad30f59319
commit f586967a56
5 changed files with 74 additions and 2 deletions

View File

@ -52,7 +52,8 @@ magnum_api_paste_ini_overrides: {}
# Name of the virtual env to deploy into
magnum_venv_tag: untagged
magnum_bin: "/openstack/venvs/magnum-{{ magnum_venv_tag }}/bin"
magnum_venv_path: "/openstack/venvs/magnum-{{ magnum_venv_tag }}"
magnum_bin: "{{ magnum_venv_path }}/bin"
# venv_download, even when true, will use the fallback method of building the
# venv from scratch if the venv download fails.
@ -114,6 +115,7 @@ magnum_pip_packages:
- magnum
- python-memcached
- osprofiler
- uwsgi
# This variable is used by the repo_build process to determine
# which host group to check for members of before building the
@ -139,3 +141,18 @@ magnum_services:
service_name: magnum-api
init_config_overrides: "{{ magnum_api_init_config_overrides }}"
start_order: 2
wsgi_overrides: "{{ magnum_api_uwsgi_ini_overrides }}"
wsgi_app: True
log_string: "--logto "
wsgi_name: lib/python2.7/site-packages/magnum/api/app.wsgi
uwsgi_port: "{{ magnum_bind_port }}"
uwsgi_bind_address: "{{ magnum_api_uwsgi_bind_address }}"
program_override: "{{ magnum_bin }}/uwsgi --ini /etc/uwsgi/magnum-api.ini"
# uWSGI Settings
magnum_api_uwsgi_ini_overrides: {}
magnum_wsgi_processes_max: 16
magnum_wsgi_processes: "{{ [[ansible_processor_vcpus|default(1), 1] | max * 2, magnum_wsgi_processes_max] | min }}"
magnum_wsgi_threads: 1
magnum_wsgi_buffer_size: 65535
magnum_api_uwsgi_bind_address: 0.0.0.0

32
tasks/magnum_uwsgi.yml Normal file
View File

@ -0,0 +1,32 @@
---
# Copyright 2017, Rackspace US, Inc.
#
# 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.
- name: Ensure uWSGI directory exists
file:
path: "/etc/uwsgi/"
state: directory
mode: "0711"
- name: Apply uWSGI configuration
config_template:
src: "magnum-uwsgi.ini.j2"
dest: "/etc/uwsgi/{{ item.service_name }}.ini"
mode: "0744"
config_overrides: "{{ item.wsgi_overrides }}"
config_type: ini
with_items: "{{ filtered_magnum_services }}"
when: item.wsgi_app | default(False)
notify:
- Restart magnum services

View File

@ -44,6 +44,10 @@
tags:
- magnum-config
- include: magnum_uwsgi.yml
tags:
- magnum-config
- include: magnum_service_setup.yml
when: inventory_hostname == groups['magnum_all'][0]
tags:

View File

@ -12,7 +12,7 @@ User={{ magnum_system_user_name }}
Group={{ magnum_system_group_name }}
{% if item.program_override is defined %}
ExecStart={{ item.program_override }} {{ item.program_config_options|default('') }} --log-file=/var/log/magnum/{{ item.service_name }}.log
ExecStart={{ item.program_override }} {{ item.program_config_options|default('') }} {{ item.log_string | default('--log-file=') }}/var/log/magnum/{{ item.service_name }}.log
{% else %}
ExecStart={{ magnum_bin }}/{{ item.service_name }} {{ item.program_config_options|default('') }} --log-file=/var/log/magnum/{{ item.service_name }}.log
{% endif %}

View File

@ -0,0 +1,19 @@
[uwsgi]
uid = {{ magnum_system_user_name }}
gid = {{ magnum_system_group_name }}
virtualenv = {{ magnum_venv_path }}
wsgi-file = {{ magnum_venv_path }}/{{ item.wsgi_name }}
http-socket = {{ item.uwsgi_bind_address }}:{{ item.uwsgi_port }}
master = true
enable-threads = true
processes = {{ magnum_wsgi_processes }}
threads = {{ magnum_wsgi_threads }}
exit-on-reload = true
die-on-term = true
lazy-apps = true
add-header = Connection: close
buffer-size = {{ magnum_wsgi_buffer_size }}
thunder-lock = true
logfile-chmod = 644