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: I54e3063d6e641a785377f9039641072f8001cf24
This commit is contained in:
parent
c1ddbfb400
commit
f3eddb3d51
@ -169,11 +169,13 @@ gnocchi_services:
|
||||
service_name: "gnocchi-api"
|
||||
service_enabled: "{{ gnocchi_use_mod_wsgi | ternary(false, true) }}"
|
||||
init_config_overrides: "{{ gnocchi_api_init_overrides }}"
|
||||
execstarts: "{{ gnocchi_bin }}/gnocchi-api"
|
||||
gnocchi-metricd:
|
||||
group: "gnocchi_metricd"
|
||||
service_name: "gnocchi-metricd"
|
||||
service_enabled: true
|
||||
init_config_overrides: "{{ gnocchi_metricd_init_overrides }}"
|
||||
execstarts: "{{ gnocchi_bin }}/gnocchi-metricd"
|
||||
|
||||
#: Common pip packages
|
||||
gnocchi_pip_packages:
|
||||
|
@ -18,7 +18,7 @@
|
||||
name: "{{ item.value.service_name }}"
|
||||
enabled: yes
|
||||
state: "stopped"
|
||||
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
|
||||
daemon_reload: yes
|
||||
with_dict: "{{ gnocchi_services }}"
|
||||
when:
|
||||
- "item.value.group in group_names"
|
||||
@ -56,7 +56,7 @@
|
||||
name: "{{ item.value.service_name }}"
|
||||
enabled: yes
|
||||
state: "started"
|
||||
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
|
||||
daemon_reload: yes
|
||||
with_dict: "{{ gnocchi_services }}"
|
||||
when:
|
||||
- "item.value.group in group_names"
|
||||
@ -74,7 +74,7 @@
|
||||
name: "{{ gnocchi_system_service_name }}"
|
||||
enabled: yes
|
||||
state: "restarted"
|
||||
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
|
||||
daemon_reload: yes
|
||||
when: gnocchi_use_mod_wsgi | bool
|
||||
register: _restart
|
||||
until: _restart is success
|
||||
|
@ -1,60 +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: "{{ gnocchi_system_user_name }}"
|
||||
group: "{{ gnocchi_system_group_name }}"
|
||||
mode: "02755"
|
||||
with_dict: "{{ gnocchi_services }}"
|
||||
when: "item.value.group in group_names"
|
||||
|
||||
- name: Create TEMP lock dir
|
||||
file:
|
||||
path: "/var/lock/{{ item.value.service_name }}"
|
||||
state: directory
|
||||
owner: "{{ gnocchi_system_user_name }}"
|
||||
group: "{{ gnocchi_system_group_name }}"
|
||||
mode: "02755"
|
||||
with_dict: "{{ gnocchi_services }}"
|
||||
when: "item.value.group in group_names"
|
||||
|
||||
- name: Create tmpfiles.d entry
|
||||
template:
|
||||
src: "gnocchi-systemd-tmpfiles.j2"
|
||||
dest: "/etc/tmpfiles.d//{{ item.value.service_name }}.conf"
|
||||
mode: "0644"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
with_dict: "{{ gnocchi_services }}"
|
||||
when: "item.value.group in group_names"
|
||||
notify:
|
||||
- Restart gnocchi services
|
||||
|
||||
- name: Place the systemd init script
|
||||
config_template:
|
||||
src: "gnocchi-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: "{{ gnocchi_services }}"
|
||||
when: "item.value.group in group_names"
|
||||
notify:
|
||||
- Restart gnocchi services
|
@ -38,10 +38,25 @@
|
||||
tags:
|
||||
- gnocchi-config
|
||||
|
||||
- include_tasks: "gnocchi_init_{{ ansible_service_mgr }}.yml"
|
||||
- name: Run the systemd service role
|
||||
include_role:
|
||||
name: systemd_service
|
||||
private: true
|
||||
vars:
|
||||
systemd_user_name: "{{ gnocchi_system_user_name }}"
|
||||
systemd_group_name: "{{ gnocchi_system_group_name }}"
|
||||
systemd_tempd_prefix: openstack
|
||||
systemd_slice_name: gnocchi
|
||||
systemd_lock_path: /var/lock/gnocchi
|
||||
systemd_CPUAccounting: true
|
||||
systemd_BlockIOAccounting: true
|
||||
systemd_MemoryAccounting: true
|
||||
systemd_TasksAccounting: true
|
||||
systemd_services: "{{ filtered_gnocchi_services }}"
|
||||
when: not gnocchi_identity_only | bool
|
||||
tags:
|
||||
- gnocchi-config
|
||||
- systemd-service
|
||||
|
||||
- include_tasks: gnocchi_service_setup.yml
|
||||
when:
|
||||
|
@ -1,30 +0,0 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
[Unit]
|
||||
Description=gnocchi openstack service
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ gnocchi_system_user_name }}
|
||||
Group={{ gnocchi_system_group_name }}
|
||||
|
||||
ExecStart={{ gnocchi_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/gnocchi/{{ item.value.service_name }}.log
|
||||
|
||||
# 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=gnocchi.slice
|
||||
CPUAccounting=true
|
||||
BlockIOAccounting=true
|
||||
MemoryAccounting=false
|
||||
TasksAccounting=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,4 +0,0 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
D /var/lock/{{ item.value.service_name }} 2755 {{ gnocchi_system_user_name }} {{ gnocchi_system_group_name }}
|
||||
D /var/run/{{ item.value.service_name }} 2755 {{ gnocchi_system_user_name }} {{ gnocchi_system_group_name }}
|
@ -23,3 +23,28 @@ gnocchi_api_paste_default_content: |
|
||||
gnocchi_policy_default_content: |
|
||||
{{ _git_file_fetch.results | selectattr('item', 'equalto', gnocchi_git_config_lookup_location ~ '/' ~ gnocchi_policy_git_file_path) | map(attribute='content') | first }}
|
||||
|
||||
filtered_gnocchi_services: |-
|
||||
{% set services = [] %}
|
||||
{% for name, service in gnocchi_services.items() %}
|
||||
{% if (service['group'] in group_names) and
|
||||
(('service_enabled' not in service) or
|
||||
('service_enabled' in service and service['service_enabled'])) %}
|
||||
{% set _ = service.update(
|
||||
{
|
||||
'service_key': name,
|
||||
'enabled': 'yes',
|
||||
'state': 'started',
|
||||
'config_overrides': service.init_config_overrides
|
||||
}
|
||||
)
|
||||
%}
|
||||
{% set _ = service.pop('init_config_overrides') -%}
|
||||
{# Note (noonedeadpunk): The following if statement is added for backwards compatability #}
|
||||
{# As up to stein release gnocchi role didn't have 'execstarts' in gnocchi_services keys #}
|
||||
{% if ('execstarts' not in service) %}
|
||||
{% set _ = service.update({'execstarts': gnocchi_bin ~ '/' ~ service.service_name}) %}
|
||||
{% endif %}
|
||||
{% set _ = services.append(service) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ services }}
|
||||
|
Loading…
Reference in New Issue
Block a user