/home/zuul/src/opendev.org/openstack/ansible-role-uwsgi/tasks/uwsgi_post_install.yml
---
# 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.

- name: Ensure uWSGI directory exists
  file:
    path: "/etc/uwsgi/"
    state: directory

- name: Deploy uWSGI configuration files
  config_template:
    src: uwsgi.ini.j2
    dest: "/etc/uwsgi/{{ item.key }}.ini"
    config_type: "ini"
    config_overrides: "{{ item.value.uwsgi_overrides | default({}) }}"
  with_dict: "{{ uwsgi_services }}"
  notify:
    - Manage LB
    - Restart uwsgi services

- name: Run the systemd service role
  include_role:
    name: systemd_service
  vars:
    systemd_user_name: "{{ service_var.value.uwsgi_uid | default(uwsgi_system_user_name) }}"
    systemd_group_name: "{{ service_var.value.uwsgi_uid | default(uwsgi_system_user_name) }}"
    systemd_tempd_prefix: openstack
    systemd_slice_name: uwsgi
    systemd_lock_path: "/var/lock/uwsgi"
    systemd_CPUAccounting: true
    systemd_BlockIOAccounting: true
    systemd_MemoryAccounting: true
    systemd_TasksAccounting: true
    systemd_services:
      - service_name: "{{ service_var.value.service_name | default(service_var.key) }}"
        enabled: yes
        state: started
        execstarts: "{{ uwsgi_bin }}/uwsgi --autoload --ini /etc/uwsgi/{{ service_var.key }}.ini"
        execreloads: "{{ uwsgi_bin }}/uwsgi --reload /var/run/{{ service_var.key }}/{{ service_var.key }}.pid"
        config_overrides: "{{ service_var.value.init_config_overrides | default({}) }}"
  with_dict: "{{ uwsgi_services }}"
  loop_control:
    loop_var: service_var