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. The exterior role is built to be OSA compatible and may be pulled
into tree should we deem it necessary.

Change-Id: Id833d4ecf9d17bb74c1c0702c00ace241ac48873
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-03-30 23:06:06 -05:00
parent a84add9575
commit 51fa0eb892
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
9 changed files with 55 additions and 197 deletions

View File

@ -29,10 +29,6 @@ trove_system_user_home: "/var/lib/{{ trove_system_user_name }}"
trove_log_directory: /var/log/trove
trove_etc_directory: /etc/trove
trove_api_program_name: trove-api
trove_conductor_program_name: trove-conductor
trove_taskmanager_program_name: trove-taskmanager
trove_admin_user_name: admin_trove_user
trove_service_name: trove
@ -185,9 +181,6 @@ trove_service_user_domain_name: default
trove_service_project_domain_id: default
trove_service_user_domain_id: default
trove_conductor_service_name: "{{ trove_conductor_program_name }}"
trove_taskmanager_service_name: "{{ trove_taskmanager_program_name }}"
#Glance images
trove_glance_images: []
@ -226,3 +219,24 @@ trove_policy_overrides: {}
trove_api_init_config_overrides: {}
trove_conductor_init_config_overrides: {}
trove_taskmanager_init_config_overrides: {}
## Service Name-Group Mapping
trove_services:
trove-api:
group: trove_api
service_name: trove-api
execstarts: "{{ trove_bin }}/trove-api"
init_config_overrides: "{{ trove_api_init_config_overrides }}"
start_order: 1
trove-conductor:
group: trove_conductor
service_name: trove-conductor
execstarts: "{{ trove_bin }}/trove-conductor"
init_config_overrides: "{{ trove_conductor_init_config_overrides }}"
start_order: 2
trove-taskmanager:
group: trove_taskmanager
service_name: trove-taskmanager
execstarts: "{{ trove_bin }}/trove-taskmanager"
init_config_overrides: "{{ trove_taskmanager_init_config_overrides }}"
start_order: 3

View File

@ -16,23 +16,21 @@
# (c) 2016 Donovan Francesco <donovan.francesco@is.co.za>
# (c) 2016 Paul Stevens <paul.stevens@is.co.za>
- name: Restart trove API services
service:
name: "{{ trove_api_program_name }}"
systemd:
name: "{{ trove_services['trove-api']['service_name'] }}"
state: "restarted"
failed_when: false
when: not trove_use_mod_wsgi | bool
when:
- not trove_use_mod_wsgi | bool
- name: Restart trove conductor service
service:
name: "{{ trove_conductor_service_name }}"
systemd:
name: "{{ trove_services['trove-conductor']['service_name'] }}"
state: "restarted"
failed_when: false
- name: Restart trove taskmanager service
service:
name: "{{ trove_taskmanager_service_name }}"
systemd:
name: "{{ trove_services['trove-conductor']['service_name'] }}"
state: "restarted"
failed_when: false
- name: Restart Apache
service:

View File

@ -53,9 +53,32 @@
- trove-install
- trove-config
- include: trove_init.yml
- name: Run the systemd service role
include_role:
name: systemd_service
private: true
vars:
systemd_user_name: "{{ trove_system_user_name }}"
systemd_group_name: "{{ trove_system_group_name }}"
systemd_tempd_prefix: openstack
systemd_slice_name: trove
system_lock_path: /var/lock/trove
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: "{{ trove_services.values() | list }}"
loop_control:
loop_var: service_var
tags:
- trove-install
- trove-config
- include: trove_service_setup.yml
when: inventory_hostname == groups['trove_api'][0]

View File

@ -18,7 +18,7 @@
- name: Perform a trove DB sync
command: >
{{ trove_bin }}/trove-manage
--config-file=/etc/trove/{{ trove_conductor_program_name }}.conf
--config-file=/etc/trove/{{ trove_services['trove-conductor']['service_name'] }}.conf
db_sync {{ trove_db_sync_options }}
become: yes
become_user: "{{ trove_system_user_name }}"

View File

@ -1,46 +0,0 @@
---
# Copyright 2016 Internet Solutions (Pty) Ltd
#
# 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.
#
# (c) 2016 Donovan Francesco <donovan.francesco@is.co.za>
# (c) 2016 Paul Stevens <paul.stevens@is.co.za>
- include: trove_init_common.yml
vars:
program_name: "{{ trove_api_program_name }}"
service_name: "{{ trove_service_name }}"
system_user: "{{ trove_system_user_name }}"
system_group: "{{ trove_system_group_name }}"
service_home: "{{ trove_system_user_home }}"
init_config_overrides: "{{ trove_api_init_config_overrides }}"
when: inventory_hostname in groups['trove_api']
- include: trove_init_common.yml
vars:
program_name: "{{ trove_conductor_program_name }}"
service_name: "{{ trove_conductor_service_name }}"
system_user: "{{ trove_system_user_name }}"
system_group: "{{ trove_system_group_name }}"
service_home: "{{ trove_system_user_home }}"
init_config_overrides: "{{ trove_conductor_init_config_overrides }}"
when: inventory_hostname in groups['trove_conductor']
- include: trove_init_common.yml
vars:
program_name: "{{ trove_taskmanager_program_name }}"
service_name: "{{ trove_taskmanager_service_name }}"
system_user: "{{ trove_system_user_name }}"
system_group: "{{ trove_system_group_name }}"
service_home: "{{ trove_system_user_home }}"
init_config_overrides: "{{ trove_taskmanager_init_config_overrides }}"
when: inventory_hostname in groups['trove_taskmanager']

View File

@ -1,32 +0,0 @@
---
# Copyright 2016 Internet Solutions (Pty) Ltd
#
# 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.
#
# (c) 2016 Donovan Francesco <donovan.francesco@is.co.za>
# (c) 2016 Paul Stevens <paul.stevens@is.co.za>
- include: trove_init_systemd.yml
static: no
when:
- ansible_service_mgr == 'systemd'
- name: Load service
service:
name: "{{ program_name }}"
enabled: "yes"
notify:
- Restart trove API services
- Restart trove conductor service
- Restart trove taskmanager service
- Restart Apache

View File

@ -1,61 +0,0 @@
---
# Copyright 2016 Internet Solutions (Pty) Ltd
#
# 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.
#
# (c) 2016 Donovan Francesco <donovan.francesco@is.co.za>
# (c) 2016 Paul Stevens <paul.stevens@is.co.za>
- name: Create TEMP run dir
file:
path: "/var/run/{{ program_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
mode: "02755"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ program_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
mode: "02755"
- name: Create tempfile.d entry
template:
src: "trove-systemd-tempfiles.j2"
dest: "/etc/tmpfiles.d/trove.conf"
mode: "0644"
owner: "root"
group: "root"
- name: Place the systemd init script
config_template:
src: "trove-systemd-init.j2"
dest: "/etc/systemd/system/{{ program_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_overrides: "{{ init_config_overrides }}"
config_type: "ini"
register: systemd_init
- name: Reload the systemd daemon
systemd:
daemon_reload: true
when: systemd_init | changed
notify:
- Restart trove API services
- Restart trove conductor service
- Restart trove taskmanager service
- Restart Apache

View File

@ -1,34 +0,0 @@
# {{ ansible_managed }}
[Unit]
Description=trove openstack service
After=syslog.target
After=network.target
[Service]
Type=simple
User={{ system_user }}
Group={{ system_group }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/trove/{{ program_name }}.log
{% else %}
ExecStart={{ trove_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/trove/{{ program_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=trove.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/{{ program_name }} 2755 {{ system_user }} {{ system_group }}
D /var/run/{{ program_name }} 2755 {{ system_user }} {{ system_group }}