From 2b5fe2ef790c452f69f9fc2373944f49f0c1e959 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Wed, 2 Aug 2017 13:48:11 -0500 Subject: [PATCH] Implement uWSGI for heat api services As part of the Pike goals we are moving api services to run as WSGI apps. heat-api, heat-api-cfn, and heat-api-cloudwatch are now set up as WSGI apps. Since this is just a drop in replacement for existing eventlet services, operators and deployers should not notice a difference. Change-Id: I3dba17c33a7f1a1b9a03020a650e258099b4d20d Implements: blueprint goal-deploy-api-in-wsgi --- defaults/main.yml | 34 +++++++++++++++++++ .../notes/heat_uwsgi-11d691aa4d47c35d.yaml | 20 +++++++++++ tasks/heat_uwsgi.yml | 32 +++++++++++++++++ tasks/main.yml | 4 +++ templates/heat-systemd-init.j2 | 6 ++-- templates/heat-uwsgi.ini.j2 | 19 +++++++++++ 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/heat_uwsgi-11d691aa4d47c35d.yaml create mode 100644 tasks/heat_uwsgi.yml create mode 100644 templates/heat-uwsgi.ini.j2 diff --git a/defaults/main.yml b/defaults/main.yml index f241d27..1572a6c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -206,6 +206,7 @@ heat_pip_packages: - python-openstackclient - python-swiftclient - python-troveclient + - uwsgi heat_api_init_overrides: {} heat_api_cfn_init_overrides: {} @@ -219,16 +220,37 @@ heat_services: service_name: heat-api init_config_overrides: "{{ heat_api_init_overrides }}" start_order: 2 + wsgi_overrides: "{{ heat_api_uwsgi_ini_overrides }}" + wsgi_app: True + log_string: "--logto " + wsgi_name: heat-wsgi-api + uwsgi_port: "{{ heat_service_port }}" + uwsgi_bind_address: "{{ heat_api_uwsgi_bind_address }}" + program_override: "{{ heat_bin }}/uwsgi --ini /etc/uwsgi/heat-api.ini" heat-api-cfn: group: heat_api_cfn service_name: heat-api-cfn init_config_overrides: "{{ heat_api_cfn_init_overrides }}" start_order: 3 + wsgi_overrides: "{{ heat_api_cfn_uwsgi_ini_overrides }}" + wsgi_app: True + log_string: "--logto " + wsgi_name: heat-wsgi-api-cfn + uwsgi_port: "{{ heat_cfn_service_port }}" + uwsgi_bind_address: "{{ heat_api_cfn_uwsgi_bind_address }}" + program_override: "{{ heat_bin }}/uwsgi --ini /etc/uwsgi/heat-api-cfn.ini" heat-api-cloudwatch: group: heat_api_cloudwatch service_name: heat-api-cloudwatch init_config_overrides: "{{ heat_api_cloudwatch_init_overrides }}" start_order: 3 + wsgi_overrides: "{{ heat_api_cloudwatch_uwsgi_ini_overrides }}" + wsgi_app: True + log_string: "--logto " + wsgi_name: heat-wsgi-api-cloudwatch + uwsgi_port: "{{ heat_watch_port }}" + uwsgi_bind_address: "{{ heat_api_cloudwatch_uwsgi_bind_address }}" + program_override: "{{ heat_bin }}/uwsgi --ini /etc/uwsgi/heat-api-cloudwatch.ini" heat-engine: group: heat_engine service_name: heat-engine @@ -245,6 +267,18 @@ heat_required_secrets: - heat_service_password - memcached_encryption_key +# uWSGI Settings +heat_api_uwsgi_ini_overrides: {} +heat_api_cfn_uwsgi_ini_overrides: {} +heat_api_cloudwatch_uwsgi_ini_overrides: {} +heat_wsgi_processes_max: 16 +heat_wsgi_processes: "{{ [[ansible_processor_vcpus|default(1), 1] | max * 2, heat_wsgi_processes_max] | min }}" +heat_wsgi_threads: 1 +heat_wsgi_buffer_size: 65535 +heat_api_uwsgi_bind_address: 0.0.0.0 +heat_api_cfn_uwsgi_bind_address: 0.0.0.0 +heat_api_cloudwatch_uwsgi_bind_address: 0.0.0.0 + # 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 diff --git a/releasenotes/notes/heat_uwsgi-11d691aa4d47c35d.yaml b/releasenotes/notes/heat_uwsgi-11d691aa4d47c35d.yaml new file mode 100644 index 0000000..18e9b7b --- /dev/null +++ b/releasenotes/notes/heat_uwsgi-11d691aa4d47c35d.yaml @@ -0,0 +1,20 @@ +--- +features: + - The ``heat-api``, ``heat-api-cfn``, and + ``heat-api-cloudwatch`` services have moved to run + as a uWSGI applications. You can set the max number + of WSGI processes, the number of processes, threads, + and buffer size utilizing the + ``heat_wsgi_processes_max``, + ``heat_wsgi_processes``, ``heat_wsgi_threads``, + and ``heat_wsgi_buffer_size``. + Additionally, you can override any settings in the + uWSGI ini configuration file using the + ``heat_api_uwsgi_ini_overrides``, + ``heat_api_cfn_uwsgi_ini_overrides``, and + ``heat_api_cloudwatch_uwsgi_ini_overrides`` settings. + The uWSGI applications will listen on the addresses + specified by ``heat_api_uwsgi_bind_address``, + ``heat_api_cfn_uwsgi_bind_address``, and + ``heat_api_cloudwatch_uwsgi_bind_address`` + respectively. Which all default to ``0.0.0.0``. diff --git a/tasks/heat_uwsgi.yml b/tasks/heat_uwsgi.yml new file mode 100644 index 0000000..a0ba272 --- /dev/null +++ b/tasks/heat_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: "heat-uwsgi.ini.j2" + dest: "/etc/uwsgi/{{ item.service_name }}.ini" + mode: "0744" + config_overrides: "{{ item.wsgi_overrides }}" + config_type: ini + with_items: "{{ filtered_heat_services }}" + when: item.wsgi_app | default(False) + notify: + - Restart heat services diff --git a/tasks/main.yml b/tasks/main.yml index 5bcc074..823aedd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -62,6 +62,10 @@ tags: - heat-config +- include: heat_uwsgi.yml + tags: + - heat-config + - include: heat_service_setup.yml static: no when: diff --git a/templates/heat-systemd-init.j2 b/templates/heat-systemd-init.j2 index 4b1aa33..1e3b10c 100644 --- a/templates/heat-systemd-init.j2 +++ b/templates/heat-systemd-init.j2 @@ -10,10 +10,10 @@ Type=simple User={{ heat_system_user_name }} Group={{ heat_system_group_name }} -{% if program_override is defined %} -ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ item.service_name }}.log +{% if item.program_override is defined %} +ExecStart={{ item.program_override }} {{ program_config_options|default('') }} {{ item.log_string | default('--log-file=') }}/var/log/heat/{{ item.service_name }}.log {% else %} -ExecStart={{ heat_bin }}/{{ item.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ item.service_name }}.log +ExecStart={{ heat_bin }}/{{ item.service_name }} {{ item.program_config_options|default('') }} --log-file=/var/log/heat/{{ item.service_name }}.log {% endif %} # Give a reasonable amount of time for the server to start up/shut down diff --git a/templates/heat-uwsgi.ini.j2 b/templates/heat-uwsgi.ini.j2 new file mode 100644 index 0000000..d63dd6b --- /dev/null +++ b/templates/heat-uwsgi.ini.j2 @@ -0,0 +1,19 @@ +[uwsgi] +uid = {{ heat_system_user_name }} +gid = {{ heat_system_group_name }} + +virtualenv = /openstack/venvs/heat-{{ heat_venv_tag }} +wsgi-file = {{ heat_bin }}/{{ item.wsgi_name }} +http-socket = {{ item.uwsgi_bind_address }}:{{ item.uwsgi_port }} + +master = true +enable-threads = true +processes = {{ heat_wsgi_processes }} +threads = {{ heat_wsgi_threads }} +exit-on-reload = true +die-on-term = true +lazy-apps = true +add-header = Connection: close +buffer-size = {{ heat_wsgi_buffer_size }} +thunder-lock = true +logfile-chmod = 644