Start using uWSGI role

Move service to use uWSGI role instead of iternal task for uwsgi
deployment. This aims to ease the maintenance of uWSGI and speedup
metal deployments as the same uwsgi environment will be used
across all services.

Change-Id: Iaca1e2f680d7281b4d8c0fd47907823a515f4240
This commit is contained in:
Dmitriy Rabotyagov 2019-09-05 18:54:29 +03:00
parent 3dce6f4b0d
commit dde6129387
8 changed files with 76 additions and 86 deletions

View File

@ -183,7 +183,6 @@ sahara_pip_packages:
- sahara
- systemd-python
- warlock
- uwsgi
sahara_optional_oslomsg_amqp1_pip_packages:
- oslo.messaging[amqp1]
@ -200,13 +199,11 @@ sahara_services:
group: sahara_api
service_name: sahara-api
init_config_overrides: "{{ sahara_api_init_overrides }}"
wsgi_overrides: "{{ sahara_api_uwsgi_ini_overrides }}"
wsgi_app: True
log_string: "--logto "
wsgi_name: sahara-wsgi-api
uwsgi_overrides: "{{ sahara_api_uwsgi_ini_overrides }}"
uwsgi_port: "{{ sahara_api_service_port }}"
uwsgi_bind_address: "{{ sahara_api_bind_address }}"
execstarts: "{{ sahara_bin }}/uwsgi --ini /etc/uwsgi/sahara-api.ini"
sahara-engine:
group: sahara_engine
service_name: sahara-engine
@ -217,7 +214,6 @@ sahara_services:
sahara_wsgi_processes_max: 16
sahara_wsgi_processes: "{{ [[ansible_processor_vcpus|default(1), 1] | max * 2, sahara_wsgi_processes_max] | min }}"
sahara_wsgi_threads: 1
sahara_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

View File

@ -13,10 +13,10 @@
- name: Restart sahara services
systemd:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
state: "restarted"
daemon_reload: yes
with_dict: "{{ sahara_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_sahara_services }}"
when: inventory_hostname in groups[item.group]
listen:
- "venv changed"

View File

@ -85,9 +85,15 @@
tags:
- sahara-config
- import_tasks: sahara_uwsgi.yml
- name: Import uwsgi role
import_role:
name: uwsgi
vars:
uwsgi_services: "{{ uwsgi_sahara_services }}"
uwsgi_install_method: "source"
tags:
- sahara-config
- uwsgi
- name: Run the systemd service role
import_role:
@ -102,29 +108,7 @@
systemd_BlockIOAccounting: true
systemd_MemoryAccounting: true
systemd_TasksAccounting: true
systemd_services: |-
{% set services = [] %}
{% for key, value in sahara_services.items() %}
{% if value['group'] in group_names %}
{% set _ = value.update(
{
'service_key': key,
'enabled': 'yes',
'state': 'started',
'config_overrides': value.init_config_overrides
}
)
%}
{% set _ = value.pop('init_config_overrides') %}
{# Note (noonedeadpunk): The following condition is added for backwards compatability #}
{# As up to train release sahara role didn't have 'execstarts' in sahara_services keys #}
{% if ('execstarts' not in value) %}
{% set _ = value.update({'execstarts': value.program_override | default(sahara_bin ~ '/' ~ value.service_name)}) %}
{% endif %}
{% set _ = services.append(value) %}
{% endif %}
{% endfor %}
{{ services }}
systemd_services: "{{ filtered_sahara_services }}"
tags:
- sahara-config
- systemd-service

View File

@ -41,6 +41,7 @@
config_type: "json"
notify:
- Restart sahara services
- Restart uwsgi services
- name: Drop rootwrap filter(s)
copy:

View File

@ -1,32 +0,0 @@
---
# 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: "sahara-uwsgi.ini.j2"
dest: "/etc/uwsgi/{{ item.value.service_name }}.ini"
mode: "0744"
config_overrides: "{{ item.value.wsgi_overrides }}"
config_type: ini
with_dict: "{{ sahara_services }}"
when: item.value.wsgi_app | default(False)
notify:
- Restart sahara services

View File

@ -1,22 +0,0 @@
[uwsgi]
uid = {{ sahara_system_user_name }}
gid = {{ sahara_system_group_name }}
virtualenv = /openstack/venvs/sahara-{{ sahara_venv_tag }}
wsgi-file = {{ sahara_bin }}/{{ item.value.wsgi_name }}
http-socket = {{ item.value.uwsgi_bind_address }}:{{ item.value.uwsgi_port }}
master = true
enable-threads = true
processes = {{ sahara_wsgi_processes }}
threads = {{ sahara_wsgi_threads }}
exit-on-reload = true
die-on-term = true
lazy-apps = true
add-header = Connection: close
buffer-size = {{ sahara_wsgi_buffer_size }}
thunder-lock = true
disable-logging = true
# Avoid filling up the logs with health check requests from haproxy.
route-user-agent = ^osa-haproxy-healthcheck$ donotlog:

View File

@ -63,3 +63,7 @@
src: https://opendev.org/openstack/ansible-role-python_venv_build
scm: git
version: master
- name: uwsgi
src: https://opendev.org/openstack/ansible-role-uwsgi
scm: git
version: master

59
vars/main.yml Normal file
View File

@ -0,0 +1,59 @@
---
# Copyright 2019, VEXXHOST, 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.
filtered_sahara_services: |-
{% set services = [] %}
{% for key, value in sahara_services.items() %}
{% if value['group'] in group_names and not ('wsgi_app' in value and value['wsgi_app']) %}
{% set _ = value.update(
{
'service_key': key,
'enabled': 'yes',
'state': 'started',
'config_overrides': value.init_config_overrides
}
)
%}
{% set _ = value.pop('init_config_overrides') %}
{# Note (noonedeadpunk): The following condition is added for backwards compatability #}
{# As up to train release sahara role didn't have 'execstarts' in sahara_services keys #}
{% if ('execstarts' not in value) %}
{% set _ = value.update({'execstarts': value.program_override | default(sahara_bin ~ '/' ~ value.service_name)}) %}
{% endif %}
{% set _ = services.append(value) %}
{% endif %}
{% endfor %}
{{ services }}
uwsgi_sahara_services: |-
{% set services = {} %}
{% for key, value in sahara_services.items() %}
{% if (value['group'] in group_names) and
(('condition' not in value) or ('condition' in value and value['condition']))
and ('wsgi_app' in value and value['wsgi_app']) %}
{% set _ = value.update(
{
'wsgi_path': sahara_bin ~ '/' ~ value.wsgi_name,
'wsgi_venv': sahara_bin | dirname,
'uwsgi_uid': sahara_system_user_name,
'uwsgi_guid': sahara_system_group_name,
'uwsgi_processes': sahara_wsgi_processes,
'uwsgi_threads': sahara_wsgi_threads
}
) %}
{% set _ = services.update({key: value}) %}
{% endif %}
{% endfor %}
{{ services }}