Ensure that services restart in a particular order

Currently when multiple services share a host, the
restart order is random. This is due to an unordered
dict being used to facilitate the mapping of services
to their groups, names and other options.

This patch implements changes to the role to ensure
that services on the same host are restarted in the
correct order when the software/config changes.

Change-Id: I52fc66f861ce98cc8299c84edcfd5f18d74306b3
This commit is contained in:
Jesse Pretorius 2017-06-30 13:26:44 +01:00
parent a1e3588769
commit 545e362b05
6 changed files with 52 additions and 26 deletions

View File

@ -229,10 +229,12 @@ glance_services:
group: glance_api
service_name: glance-api
init_config_overrides: "{{ glance_api_init_overrides }}"
start_order: 1
glance-registry:
group: glance_registry
service_name: glance-registry
init_config_overrides: "{{ glance_registry_init_overrides }}"
start_order: 2
# This variable is used by the repo_build process to determine
# which host group to check for members of before building the

View File

@ -22,12 +22,11 @@
- name: Stop services
service:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "stopped"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
register: _stop
until: _stop | success
retries: 5
@ -52,12 +51,11 @@
- name: Start services
service:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "started"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
register: _start
until: _start | success
retries: 5

View File

@ -15,56 +15,51 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ item.value.service_name }}"
path: "/var/run/{{ item.service_name }}"
state: directory
owner: "{{ glance_system_user_name }}"
group: "{{ glance_system_group_name }}"
mode: "02755"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ item.value.service_name }}"
path: "/var/lock/{{ item.service_name }}"
state: directory
owner: "{{ glance_system_user_name }}"
group: "{{ glance_system_group_name }}"
mode: "02755"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
# TODO(mgariepy):
# 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"
path: "/etc/tmpfiles.d/{{ item.service_name }}.conf"
state: absent
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
- name: Create tmpfiles.d entry
template:
src: "glance-systemd-tmpfiles.j2"
dest: "/etc/tmpfiles.d/openstack-{{ item.value.service_name }}.conf"
dest: "/etc/tmpfiles.d/openstack-{{ item.service_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
notify:
- Restart glance services
- name: Place the systemd init script
config_template:
src: "glance-systemd-init.j2"
dest: "/etc/systemd/system/{{ item.value.service_name }}.service"
dest: "/etc/systemd/system/{{ item.service_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_overrides: "{{ item.value.init_config_overrides }}"
config_overrides: "{{ item.init_config_overrides }}"
config_type: "ini"
with_dict: "{{ glance_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_glance_services }}"
notify:
- Restart glance services

View File

@ -11,9 +11,9 @@ User={{ glance_system_user_name }}
Group={{ glance_system_group_name }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/glance/{{ item.value.service_name }}.log
ExecStart={{ program_override }} {{ program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log
{% else %}
ExecStart={{ glance_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/glance/{{ item.value.service_name }}.log
ExecStart={{ glance_bin }}/{{ item.service_name }} {{ program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log
{% endif %}
# Give a reasonable amount of time for the server to start up/shut down

View File

@ -1,4 +1,4 @@
# {{ ansible_managed }}
D /var/lock/{{ item.value.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }}
D /var/run/{{ item.value.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }}
D /var/lock/{{ item.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }}
D /var/run/{{ item.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }}

31
vars/main.yml Normal file
View File

@ -0,0 +1,31 @@
---
# 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.
#
# 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_glance_services: |-
{% set services = [] %}
{% for key, value in glance_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') }}