From b9af252909dc4cf3b68dc9da5047b7b6b5511c9b Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 18 Jul 2019 13:04:31 +0300 Subject: [PATCH] Convert systemd services to common role(s) This removes the systemd service templates and tasks from this role and leverages a common systemd service role instead. This change removes a lot of code duplication across all roles all without sacrificing features or functionality. The intention of this change is to ensure uniformity and reduce the maintenance burden on the community when sweeping changes are needed. The exterior role is built to be OSA compatible and may be pulled into tree should we deem it necessary. Change-Id: If8a201dd964ea769c688f78abc2a688782e3be4d --- defaults/main.yml | 3 +- tasks/main.yml | 38 +++++++++++++++- tasks/sahara_init_common.yml | 25 ---------- tasks/sahara_init_systemd.yml | 68 ---------------------------- templates/sahara-systemd-init.j2 | 34 -------------- templates/sahara-systemd-tmpfiles.j2 | 4 -- 6 files changed, 39 insertions(+), 133 deletions(-) delete mode 100644 tasks/sahara_init_common.yml delete mode 100644 tasks/sahara_init_systemd.yml delete mode 100644 templates/sahara-systemd-init.j2 delete mode 100644 templates/sahara-systemd-tmpfiles.j2 diff --git a/defaults/main.yml b/defaults/main.yml index f5e3ec4..422ccbc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -205,11 +205,12 @@ sahara_services: wsgi_name: sahara-wsgi-api uwsgi_port: "{{ sahara_api_service_port }}" uwsgi_bind_address: "{{ sahara_api_bind_address }}" - program_override: "{{ sahara_bin }}/uwsgi --ini /etc/uwsgi/sahara-api.ini" + execstarts: "{{ sahara_bin }}/uwsgi --ini /etc/uwsgi/sahara-api.ini" sahara-engine: group: sahara_engine service_name: sahara-engine init_config_overrides: "{{ sahara_engine_init_overrides }}" + execstarts: "{{ sahara_bin }}/sahara-engine" ## Sahara uWSGI settings sahara_wsgi_processes_max: 16 diff --git a/tasks/main.yml b/tasks/main.yml index 9d9742e..b7f31dd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -89,9 +89,45 @@ tags: - sahara-config -- import_tasks: sahara_init_common.yml +- name: Run the systemd service role + import_role: + name: systemd_service + vars: + systemd_user_name: "{{ sahara_system_user_name }}" + systemd_group_name: "{{ sahara_system_group_name }}" + systemd_tempd_prefix: openstack + systemd_slice_name: sahara + systemd_lock_path: /var/lock/sahara + systemd_CPUAccounting: true + 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 }} tags: - sahara-config + - systemd-service - import_tasks: sahara_db_sync.yml when: inventory_hostname == groups['sahara_all'][0] diff --git a/tasks/sahara_init_common.yml b/tasks/sahara_init_common.yml deleted file mode 100644 index 295baad..0000000 --- a/tasks/sahara_init_common.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -# 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. - -- include_tasks: sahara_init_systemd.yml - when: - - ansible_service_mgr == 'systemd' - -- name: Load service - service: - name: "{{ item.value.service_name }}" - enabled: "yes" - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - notify: - - Restart sahara services diff --git a/tasks/sahara_init_systemd.yml b/tasks/sahara_init_systemd.yml deleted file mode 100644 index d01cad5..0000000 --- a/tasks/sahara_init_systemd.yml +++ /dev/null @@ -1,68 +0,0 @@ ---- -# Copyright 2016, 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: Create TEMP run dir - file: - path: "/var/run/{{ item.value.service_name }}" - state: directory - owner: "{{ sahara_system_user_name }}" - group: "{{ sahara_system_group_name }}" - mode: "02755" - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - -- name: Create TEMP lock dir - file: - path: "/var/lock/{{ item.value.service_name }}" - state: directory - owner: "{{ sahara_system_user_name }}" - group: "{{ sahara_system_group_name }}" - mode: "02755" - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - -# TODO: -# Remove this in Pike as it only needed to handle upgrades -# from Newton->Newton and Newton->Ocata -- name: Cleanup old tmpfiles.d entry - file: - path: "/etc/tmpfiles.d/{{ item.value.service_name }}.conf" - state: absent - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - -- name: Create tmpfiles.d entry - template: - src: "sahara-systemd-tmpfiles.j2" - dest: "/etc/tmpfiles.d/openstack-{{ item.value.service_name }}.conf" - mode: "0644" - owner: "root" - group: "root" - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - -- name: Place the systemd init script - config_template: - src: "sahara-systemd-init.j2" - dest: "/etc/systemd/system/{{ item.value.service_name }}.service" - mode: "0644" - owner: "root" - group: "root" - config_overrides: "{{ item.value.init_config_overrides }}" - config_type: "ini" - with_dict: "{{ sahara_services }}" - when: inventory_hostname in groups[item.value.group] - notify: - - Restart sahara services diff --git a/templates/sahara-systemd-init.j2 b/templates/sahara-systemd-init.j2 deleted file mode 100644 index 31a4da7..0000000 --- a/templates/sahara-systemd-init.j2 +++ /dev/null @@ -1,34 +0,0 @@ -# {{ ansible_managed }} - -[Unit] -Description=sahara openstack service -After=syslog.target -After=network.target - -[Service] -Type=simple -User={{ sahara_system_user_name }} -Group={{ sahara_system_group_name }} - -{% if item.value.program_override is defined %} -ExecStart={{ item.value.program_override }} {{ item.value.program_config_options|default('') }} {{ item.value.log_string | default('--log-file=') }}/var/log/sahara/{{ item.value.service_name }}.log -{% else %} -ExecStart={{ sahara_bin }}/{{ item.value.service_name }} {{ item.value.program_config_options|default('') }} --log-file=/var/log/sahara/{{ item.value.service_name }}.log -{% endif %} - -# Give a reasonable amount of time for the server to start up/shut down -TimeoutSec=120 -Restart=on-failure -RestartSec=2 - -# This creates a specific slice which all services will operate from -# The accounting options give us the ability to see resource usage through -# the `systemd-cgtop` command. -Slice=sahara.slice -CPUAccounting=true -BlockIOAccounting=true -MemoryAccounting=false -TasksAccounting=true - -[Install] -WantedBy=multi-user.target diff --git a/templates/sahara-systemd-tmpfiles.j2 b/templates/sahara-systemd-tmpfiles.j2 deleted file mode 100644 index f62fd3a..0000000 --- a/templates/sahara-systemd-tmpfiles.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} - -D /var/lock/{{ item.value.service_name }} 2755 {{ sahara_system_user_name }} {{ sahara_system_group_name }} -D /var/run/{{ item.value.service_name }} 2755 {{ sahara_system_user_name }} {{ sahara_system_group_name }}