From 8c2f4b0b7cd802150bf707d8b92671a2c4077938 Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Fri, 21 Jul 2017 13:38:15 +0100 Subject: [PATCH] Implement uWSGI for glance-api As part of the Pike goals we are moving api services to run as WSGI apps. glance-api service is set up as a wsgi app, and this patch moves it over. Since this is just a drop in replacement for the existing eventlet service operators and deployers should notice no difference. Implements: blueprint goal-deploy-api-in-wsgi Change-Id: Ie5fbf437031be01682534c466b3737d090a81c57 --- defaults/main.yml | 15 +++++++++ .../notes/glance_uwsgi-dd5fe62e6f85ecd2.yaml | 12 +++++++ tasks/glance_uwsgi.yml | 32 +++++++++++++++++++ tasks/main.yml | 4 +++ templates/glance-systemd-init.j2 | 4 +-- templates/glance-uwsgi.ini.j2 | 19 +++++++++++ 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/glance_uwsgi-dd5fe62e6f85ecd2.yaml create mode 100644 tasks/glance_uwsgi.yml create mode 100644 templates/glance-uwsgi.ini.j2 diff --git a/defaults/main.yml b/defaults/main.yml index ad73b18e..b9e95cc1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -218,6 +218,7 @@ glance_pip_packages: - python-keystoneclient - python-memcached - python-swiftclient + - uwsgi - warlock glance_api_init_overrides: {} @@ -230,12 +231,25 @@ glance_services: service_name: glance-api init_config_overrides: "{{ glance_api_init_overrides }}" start_order: 1 + wsgi_overrides: "{{ glance_api_uwsgi_ini_overrides }}" + wsgi_app: True + log_string: "--logto " + wsgi_name: glance-wsgi-api + uwsgi_bind_address: "{{glance_api_bind_address }}" + uwsgi_port: "{{ glance_api_service_port }}" + program_override: "{{ glance_bin }}/uwsgi --ini /etc/uwsgi/glance-api.ini" glance-registry: group: glance_registry service_name: glance-registry init_config_overrides: "{{ glance_registry_init_overrides }}" start_order: 2 +# Glance uWSGI settings +glance_wsgi_processes_max: 16 +glance_wsgi_processes: "{{ [[ansible_processor_vcpus|default(1), 1] | max * 2, glance_wsgi_processes_max] | min }}" +glance_wsgi_threads: 1 +glance_wsgi_buffer_size: 65535 + # This variable is used by the repo_build process to determine # which host group to check for members of before building the # pip packages required by this role. The value is picked up @@ -253,3 +267,4 @@ glance_glance_scrubber_conf_overrides: {} glance_glance_scheme_json_overrides: {} glance_glance_swift_store_conf_overrides: {} glance_policy_overrides: {} +glance_api_uwsgi_ini_overrides: {} diff --git a/releasenotes/notes/glance_uwsgi-dd5fe62e6f85ecd2.yaml b/releasenotes/notes/glance_uwsgi-dd5fe62e6f85ecd2.yaml new file mode 100644 index 00000000..989e3264 --- /dev/null +++ b/releasenotes/notes/glance_uwsgi-dd5fe62e6f85ecd2.yaml @@ -0,0 +1,12 @@ +--- +features: + - The ``glance-api`` service has moved to run as a + uWSGI application. You can set the max number of WSGI + processes, the number of processes, threads, and + buffer size utilizing the + ``glance_wsgi_processes_max``, + ``glance_wsgi_processes``, ``glance_wsgi_threads``, + and ``glance_wsgi_buffer_size``. + Additionally, you can override any settings in the + uWSGI ini configuration file using the + ``glance_api_uwsgi_ini_overrides`` setting. diff --git a/tasks/glance_uwsgi.yml b/tasks/glance_uwsgi.yml new file mode 100644 index 00000000..69539344 --- /dev/null +++ b/tasks/glance_uwsgi.yml @@ -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: "glance-uwsgi.ini.j2" + dest: "/etc/uwsgi/{{ item.service_name }}.ini" + mode: "0744" + config_overrides: "{{ item.wsgi_overrides }}" + config_type: ini + with_items: "{{ filtered_glance_services }}" + when: item.wsgi_app | default(False) + notify: + - Restart glance services diff --git a/tasks/main.yml b/tasks/main.yml index 5c9526f8..1ade8625 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -49,6 +49,10 @@ tags: - glance-config +- include: glance_uwsgi.yml + tags: + - glance-config + - include: glance_service_setup.yml static: no when: diff --git a/templates/glance-systemd-init.j2 b/templates/glance-systemd-init.j2 index 0841ad5d..53050f25 100644 --- a/templates/glance-systemd-init.j2 +++ b/templates/glance-systemd-init.j2 @@ -11,9 +11,9 @@ User={{ glance_system_user_name }} Group={{ glance_system_group_name }} {% if program_override is defined %} -ExecStart={{ program_override }} {{ program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log +ExecStart={{ item.program_override }} {{ item.program_config_options | default('') }} {{ item.log_string | default('--log-file=') }}/var/log/glance/{{ item.service_name }}.log {% else %} -ExecStart={{ glance_bin }}/{{ item.service_name }} {{ program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log +ExecStart={{ glance_bin }}/{{ item.service_name }} {{ item.program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log {% endif %} # Give a reasonable amount of time for the server to start up/shut down diff --git a/templates/glance-uwsgi.ini.j2 b/templates/glance-uwsgi.ini.j2 new file mode 100644 index 00000000..610370e7 --- /dev/null +++ b/templates/glance-uwsgi.ini.j2 @@ -0,0 +1,19 @@ +[uwsgi] +uid = {{ glance_system_user_name }} +gid = {{ glance_system_group_name }} + +virtualenv = /openstack/venvs/glance-{{ glance_venv_tag }} +wsgi-file = {{ glance_bin }}/{{ item.wsgi_name }} +http-socket = {{ item.uwsgi_bind_address }}:{{ item.uwsgi_port }} + +master = true +enable-threads = true +processes = {{ glance_wsgi_processes }} +threads = {{ glance_wsgi_threads }} +exit-on-reload = true +die-on-term = true +lazy-apps = true +add-header = Connection: close +buffer-size = {{ glance_wsgi_buffer_size }} +thunder-lock = true +logfile-chmod = 644