Convert role to use a common systemd service role

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.

Change-Id: Ife802766cefa8862f2b0e42f06c100b30d65edf8
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-07-30 11:29:12 -05:00
parent b8f3385eda
commit ed9e0d5399
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
12 changed files with 95 additions and 120 deletions

View File

@ -40,6 +40,7 @@ blazar_pip_packages:
- blazar
- osprofiler
- python-blazarclient
- systemd-python
## blazar developer constraint
blazar_developer_constraints:
@ -79,11 +80,17 @@ blazar_service_internaluri_proto: "{{ openstack_service_internaluri_proto | defa
blazar_service_password: password
## Service name
blazar_service:
blazar_services:
blazar-api:
group: blazar_all
service_name: blazar-api
execstarts: "{{ blazar_bin }}/blazar-api {{ blazar_config_option }}"
init_config_overrides: "{{ blazar_api_init_config_overrides }}"
blazar-manager:
group: blazar_all
service_name: blazar-manager
execstarts: "{{ blazar_bin }}/blazar-manager {{ blazar_config_option }}"
init_config_overrides: "{{ blazar_manager_init_config_overrides }}"
## Keystone
blazar_service_project_domain_id: default
@ -102,3 +109,5 @@ blazar_program_name: blazar-server
## Tunable overrides
blazar_blazar_api_paste_ini_overrides: {}
blazar_blazar_conf_overrides: {}
blazar_api_init_config_overrides: {}
blazar_manager_init_config_overrides: {}

View File

@ -15,11 +15,8 @@
# limitations under the License.
- name: Restart blazar services
service:
name: "{{ item }}"
enabled: yes
systemd:
name: "{{ item.service_name }}"
state: restarted
pattern: "{{ item }}"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ blazar_service_names }}"
with_items: "{{ filtered_blazar_services }}"
failed_when: false

View File

@ -0,0 +1,5 @@
---
deprecations:
- The log path, ``/var/log/blazar`` is no longer used to capture service
logs. All logging for the blazar service will now be sent directly to the
systemd journal.

View File

@ -1,56 +0,0 @@
---
# Copyright 2018, taseer94@gmail.com
# All rights reserved.
#
# 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.service_name }}"
state: directory
owner: "{{ blazar_system_user_name }}"
group: "{{ blazar_system_group_name }}"
mode: "02755"
with_items: "{{ blazar_services }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ item.service_name }}"
state: directory
owner: "{{ blazar_system_user_name }}"
group: "{{ blazar_system_group_name }}"
mode: "02755"
with_items: "{{ blazar_services }}"
- name: Create tmpfiles.d entry
template:
src: "blazar-systemd-tmpfiles.j2"
dest: "/etc/tmpfiles.d/openstack-{{ item.service_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_items: "{{ blazar_services }}"
notify:
- Restart blazar services
- name: Place the systemd init script
config_template:
src: "blazar-systemd-init.j2"
dest: "/etc/systemd/system/{{ item.service_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_type: "ini"
with_items: "{{ blazar_services }}"
notify:
- Restart blazar services

View File

@ -25,6 +25,18 @@
retries: 5
delay: 2
- name: Install distro packages
package:
name: "{{ almanach_developer_mode_distro_packages }}"
state: "{{ blazar_package_state }}"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
when: blazar_developer_mode | bool
register: install_packages
until: install_packages is success
retries: 5
delay: 2
- name: Create developer mode constraint file
copy:
dest: "/opt/developer-pip-constraints.txt"

View File

@ -41,24 +41,3 @@
mode: "0755"
group: "{{ blazar_system_group_name }}"
owner: "{{ blazar_system_user_name }}"
- name: test for log directory or link
shell: |
if [ -h "/var/log/blazar" ]; then
chown -h {{ blazar_system_user_name }}:{{ blazar_system_group_name }} "/var/log/blazar"
chown -R {{ blazar_system_user_name }}:{{ blazar_system_group_name }} "$(readlink /var/log/blazar)"
else
exit 1
fi
register: log_dir
failed_when: false
changed_when: log_dir.rc != 0
- name: Create blazar log dir
file:
path: "/var/log/blazar/"
state: directory
owner: "{{ blazar_system_user_name }}"
group: "{{ blazar_system_group_name }}"
mode: "0755"
when: log_dir.rc != 0

View File

@ -38,9 +38,33 @@
tags:
- blazar-config
- include: "blazar_init_{{ ansible_service_mgr }}.yml"
- name: Run the systemd service role
include_role:
name: systemd_service
private: true
vars:
systemd_user_name: "{{ blazar_system_user_name }}"
systemd_group_name: "{{ blazar_system_group_name }}"
systemd_tempd_prefix: openstack
systemd_slice_name: blazar
systemd_lock_path: /var/lock/blazar
systemd_CPUAccounting: true
systemd_BlockIOAccounting: true
systemd_MemoryAccounting: true
systemd_TasksAccounting: true
systemd_services:
- service_name: "{{ service_var.service_name }}"
enabled: yes
state: started
execstarts: "{{ service_var.execstarts }}"
execreloads: "{{ service_var.execreloads | default([]) }}"
config_overrides: "{{ service_var.init_config_overrides }}"
with_items: "{{ filtered_blazar_services }}"
loop_control:
loop_var: service_var
tags:
- blazar-config
- systemd-service
- include: blazar_db_setup.yml
when:
@ -52,4 +76,4 @@
when:
- "inventory_hostname == ((groups['blazar']| intersect(ansible_play_hosts)) | list)[0]"
tags:
- blazar-config
- blazar-config

View File

@ -1,30 +0,0 @@
# {{ ansible_managed }}
[Unit]
Description=blazar openstack service
After=syslog.target
After=network.target
[Service]
Type=simple
User={{ blazar_system_user_name }}
Group={{ blazar_system_group_name }}
ExecStart={{ blazar_bin }}/{{ item.service_name }} {{ blazar_config_option }} --log-file=/var/log/blazar/{{ item.service_name }}.log
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
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=blazar.slice
CPUAccounting=true
BlockIOAccounting=true
MemoryAccounting=false
TasksAccounting=true
[Install]
WantedBy=multi-user.target

View File

@ -1,4 +0,0 @@
# {{ ansible_managed }}
D /var/lock/{{ item.service_name }} 2755 {{ blazar_system_user_name }} {{ blazar_system_group_name }}
D /var/run/{{ item.service_name }} 2755 {{ blazar_system_user_name }} {{ blazar_system_group_name }}

View File

@ -1,4 +1,6 @@
[DEFAULT]
use_journal = True
host=0.0.0.0
port={{ blazar_service_port }}

31
vars/main.yml Normal file
View File

@ -0,0 +1,31 @@
---
# Copyright 2018, 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.
#
# Compile a list of the services on a host based on whether
# the host is in the host group and the service is enabled.
# The service list is provided in the defined start order.
#
filtered_blazar_services: |-
{% set services = [] %}
{% for key, value in blazar_services.items() %}
{% if (value['group'] in group_names) and
(('condition' not in value) or
('condition' in value and value['condition'])) %}
{% set _ = value.update({'service_key': key}) %}
{% set _ = services.append(value) %}
{% endif %}
{% endfor %}
{{ services | sort(attribute='start_order') }}

View File

@ -28,3 +28,9 @@ blazar_distro_packages:
- libffi-dev
- python-setuptools
- python-mysqldb
- python-systemd
almanach_developer_mode_distro_packages:
- build-essential
- libsystemd-dev
- pkg-config