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 systemd journal would normally be populated with the standard out of a service however with the use of uwsgi this is not actually happening resulting in us only capturing the logs from the uwsgi process instead of the service itself. This change implements journal logging in the service config, which is part of OSLO logging. OSLO logging docs found here: <https://docs.openstack.org/oslo.log/3.28.1/journal.html> Change-Id: Ieff0119cb09e8971fab5b0393f023010a554edff Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
1ab9470007
commit
b78966cd09
@ -116,13 +116,17 @@ cloudkitty_processor_init_overrides: {}
|
||||
## Service Name-Group Mapping
|
||||
cloudkitty_services:
|
||||
cloudkitty-api:
|
||||
group: cloudkitty_api
|
||||
group: cloudkitty_all
|
||||
service_name: cloudkitty-api
|
||||
init_config_overrides: "{{ cloudkitty_api_init_overrides }}"
|
||||
execstarts: "{{ cloudkitty_bin }}/cloudkitty-api"
|
||||
start_order: 1
|
||||
cloudkitty-processor:
|
||||
group: cloudkitty_api
|
||||
group: cloudkitty_all
|
||||
service_name: cloudkitty-processor
|
||||
init_config_overrides: "{{ cloudkitty_processor_init_overrides }}"
|
||||
execstarts: "{{ cloudkitty_bin }}/cloudkitty-processor"
|
||||
start_order: 2
|
||||
|
||||
cloudkitty_pip_packages:
|
||||
- cloudkitty
|
||||
@ -132,6 +136,7 @@ cloudkitty_pip_packages:
|
||||
- PyMySQL
|
||||
- python-memcached
|
||||
- SQLAlchemy>=1.0.10
|
||||
- systemd-python
|
||||
- tooz
|
||||
|
||||
## (Qdrouterd) integration
|
||||
|
@ -29,8 +29,8 @@
|
||||
- include: common-tasks/os-log-dir-setup.yml
|
||||
vars:
|
||||
log_dirs:
|
||||
- src: "/openstack/log/{{ inventory_hostname }}-barbican"
|
||||
dest: "/var/log/barbican"
|
||||
- src: "/openstack/log/{{ inventory_hostname }}-cloudkitty"
|
||||
dest: "/var/log/cloudkitty"
|
||||
|
||||
roles:
|
||||
- role: "os_cloudkitty"
|
||||
|
@ -14,13 +14,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
- name: Stop services
|
||||
service:
|
||||
name: "{{ item.value.service_name }}"
|
||||
enabled: yes
|
||||
systemd:
|
||||
name: "{{ item.service_name }}"
|
||||
state: "stopped"
|
||||
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
|
||||
with_dict: "{{ cloudkitty_services }}"
|
||||
when: inventory_hostname in groups[item.value.group]
|
||||
with_items: "{{ filtered_cloudkitty_services }}"
|
||||
register: _stop
|
||||
until: _stop is success
|
||||
retries: 5
|
||||
@ -46,13 +43,10 @@
|
||||
listen: Restart cloudkitty services
|
||||
|
||||
- name: Start services
|
||||
service:
|
||||
name: "{{ item.value.service_name }}"
|
||||
enabled: yes
|
||||
systemd:
|
||||
name: "{{ item.service_name }}"
|
||||
state: "started"
|
||||
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
|
||||
with_dict: "{{ cloudkitty_services }}"
|
||||
when: inventory_hostname in groups[item.value.group]
|
||||
with_items: "{{ filtered_cloudkitty_services }}"
|
||||
register: _start
|
||||
until: _start is success
|
||||
retries: 5
|
||||
|
5
releasenotes/notes/journal-log-cfbr504hd9b49612.yaml
Normal file
5
releasenotes/notes/journal-log-cfbr504hd9b49612.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
deprecations:
|
||||
- The log path, ``/var/log/cloudkitty`` is no longer used to capture service
|
||||
logs. All logging for the cloudkitty service will now be sent directly to the
|
||||
systemd journal.
|
@ -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: "{{ cloudkitty_system_user_name }}"
|
||||
group: "{{ cloudkitty_system_group_name }}"
|
||||
mode: "02755"
|
||||
with_dict: "{{ cloudkitty_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: "{{ cloudkitty_system_user_name }}"
|
||||
group: "{{ cloudkitty_system_group_name }}"
|
||||
mode: "02755"
|
||||
with_dict: "{{ cloudkitty_services }}"
|
||||
when: inventory_hostname in groups[item.value.group]
|
||||
|
||||
- name: Create tempfile.d entry
|
||||
template:
|
||||
src: "cloudkitty-systemd-tempfiles.j2"
|
||||
dest: "/etc/tmpfiles.d/cloudkitty.conf"
|
||||
mode: "0644"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
with_dict: "{{ cloudkitty_services }}"
|
||||
when: inventory_hostname in groups[item.value.group]
|
||||
notify:
|
||||
- Restart cloudkitty services
|
||||
|
||||
- name: Place the systemd init script
|
||||
config_template:
|
||||
src: "cloudkitty-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: "{{ cloudkitty_services }}"
|
||||
when: inventory_hostname in groups[item.value.group]
|
||||
notify:
|
||||
- Restart cloudkitty services
|
@ -26,6 +26,18 @@
|
||||
retries: 5
|
||||
delay: 2
|
||||
|
||||
- name: Install developer mode distro packages
|
||||
package:
|
||||
pkg: "{{ cloudkitty_developer_mode_distro_packages }}"
|
||||
state: "{{ cloudkitty_package_state }}"
|
||||
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
|
||||
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
|
||||
when: cloudkitty_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"
|
||||
|
@ -48,35 +48,6 @@
|
||||
tags:
|
||||
- cloudkitty-dirs
|
||||
|
||||
- name: Test for log directory or link
|
||||
shell: |
|
||||
if [ -h "/var/log/cloudkitty" ]; then
|
||||
chown -h {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "/var/log/cloudkitty"
|
||||
chown -R {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "$(readlink /var/log/cloudkitty)"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
register: log_dir
|
||||
failed_when: false
|
||||
changed_when: log_dir.rc != 0
|
||||
tags:
|
||||
- cloudkitty-dirs
|
||||
- cloudkitty-logs
|
||||
|
||||
- name: Create cloudkitty log dir
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
owner: "{{ item.owner|default(cloudkitty_system_user_name) }}"
|
||||
group: "{{ item.group|default(cloudkitty_system_group_name) }}"
|
||||
mode: "{{ item.mode|default('0755') }}"
|
||||
with_items:
|
||||
- { path: "/var/log/cloudkitty" }
|
||||
when: log_dir.rc != 0
|
||||
tags:
|
||||
- cloudkitty-dirs
|
||||
- cloudkitty-logs
|
||||
|
||||
- name: Create cloudkitty report dir
|
||||
file:
|
||||
path: "{{ cloudkitty_output_basepath }}"
|
||||
|
@ -68,7 +68,33 @@
|
||||
when:
|
||||
- inventory_hostname == groups['cloudkitty_all'][0]
|
||||
|
||||
- include: "cloudkitty_init_{{ ansible_service_mgr }}.yml"
|
||||
- name: Run the systemd service role
|
||||
include_role:
|
||||
name: systemd_service
|
||||
private: true
|
||||
vars:
|
||||
systemd_user_name: "{{ cloudkitty_system_user_name }}"
|
||||
systemd_group_name: "{{ cloudkitty_system_group_name }}"
|
||||
systemd_tempd_prefix: openstack
|
||||
systemd_slice_name: cloudkitty
|
||||
systemd_lock_path: /var/lock/cloudkitty
|
||||
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_cloudkitty_services }}"
|
||||
loop_control:
|
||||
loop_var: service_var
|
||||
tags:
|
||||
- cloudkitty-config
|
||||
- systemd-service
|
||||
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
@ -1,34 +0,0 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
[Unit]
|
||||
Description=cloudkitty openstack service
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ cloudkitty_system_user_name }}
|
||||
Group={{ cloudkitty_system_group_name }}
|
||||
|
||||
{% if program_override is defined %}
|
||||
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ item.value.service_name }}.log
|
||||
{% else %}
|
||||
ExecStart={{ cloudkitty_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ 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=cloudkitty.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 {{ cloudkitty_system_user_name }} {{ cloudkitty_system_group_name }}
|
||||
D /var/run/{{ item.value.service_name }} 2755 {{ cloudkitty_system_user_name }} {{ cloudkitty_system_group_name }}
|
@ -18,3 +18,10 @@ cache_timeout: 600
|
||||
|
||||
cloudkitty_distro_packages:
|
||||
- git
|
||||
- python-systemd
|
||||
- python3-systemd
|
||||
|
||||
cloudkitty_developer_mode_distro_packages:
|
||||
- build-essential
|
||||
- git-core
|
||||
- libsystemd-dev
|
||||
|
31
vars/main.yml
Normal file
31
vars/main.yml
Normal 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_cloudkitty_services: |-
|
||||
{% set services = [] %}
|
||||
{% for key, value in cloudkitty_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') }}
|
@ -15,3 +15,7 @@
|
||||
|
||||
cloudkitty_distro_packages:
|
||||
- git
|
||||
- systemd-python
|
||||
|
||||
cloudkitty_developer_mode_distro_packages:
|
||||
- systemd-devel
|
||||
|
@ -15,3 +15,8 @@
|
||||
|
||||
cloudkitty_distro_packages:
|
||||
- git-core
|
||||
- python-systemd
|
||||
|
||||
cloudkitty_developer_mode_distro_packages:
|
||||
- pkg-config
|
||||
- systemd-devel
|
||||
|
Loading…
Reference in New Issue
Block a user