From dde6129387d96136c2924e095ac7cb641e095db0 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 5 Sep 2019 18:54:29 +0300 Subject: [PATCH] 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 --- defaults/main.yml | 6 +-- handlers/main.yml | 6 +-- tasks/main.yml | 32 ++++------------ tasks/sahara_post_install.yml | 1 + tasks/sahara_uwsgi.yml | 32 ---------------- templates/sahara-uwsgi.ini.j2 | 22 ----------- tests/ansible-role-requirements.yml | 4 ++ vars/main.yml | 59 +++++++++++++++++++++++++++++ 8 files changed, 76 insertions(+), 86 deletions(-) delete mode 100644 tasks/sahara_uwsgi.yml delete mode 100644 templates/sahara-uwsgi.ini.j2 create mode 100644 vars/main.yml diff --git a/defaults/main.yml b/defaults/main.yml index 171040e..645a3cf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml index 34bd5dc..1b2480a 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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" diff --git a/tasks/main.yml b/tasks/main.yml index 60de7d4..f0dc39a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/tasks/sahara_post_install.yml b/tasks/sahara_post_install.yml index 772fb34..04f7155 100644 --- a/tasks/sahara_post_install.yml +++ b/tasks/sahara_post_install.yml @@ -41,6 +41,7 @@ config_type: "json" notify: - Restart sahara services + - Restart uwsgi services - name: Drop rootwrap filter(s) copy: diff --git a/tasks/sahara_uwsgi.yml b/tasks/sahara_uwsgi.yml deleted file mode 100644 index ca6ebed..0000000 --- a/tasks/sahara_uwsgi.yml +++ /dev/null @@ -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 diff --git a/templates/sahara-uwsgi.ini.j2 b/templates/sahara-uwsgi.ini.j2 deleted file mode 100644 index 1b77e77..0000000 --- a/templates/sahara-uwsgi.ini.j2 +++ /dev/null @@ -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: diff --git a/tests/ansible-role-requirements.yml b/tests/ansible-role-requirements.yml index 3d040a0..f698687 100644 --- a/tests/ansible-role-requirements.yml +++ b/tests/ansible-role-requirements.yml @@ -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 diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..8510bd3 --- /dev/null +++ b/vars/main.yml @@ -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 }}