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: I83d31e3268e34d048aa6632c7999771d49f637a1
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-07-30 13:33:10 -05:00
parent 28b50f04e3
commit feef273d71
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
12 changed files with 106 additions and 127 deletions

View File

@ -47,11 +47,20 @@ congress_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/congress.tgz
## Common PIP packages
congress_pip_packages:
- congress
- osprofiler
- pymysql
- python-congressclient
- python-heatclient
- congress
- osprofiler
- pymysql
- python-congressclient
- python-heatclient
- systemd-python
congress_services:
congress-server:
group: congress_all
service_name: congress-server
execstarts: "{{ congress_bin }}/congress-server --config-file={{ congress_etc_dir }}/congress.conf"
init_config_overrides: "{{ congress_server_init_overrides }}"
start_order: 1
## System info
congress_system_user_name: congress
@ -59,7 +68,6 @@ congress_system_group_name: congress
congress_system_shell: /bin/false
congress_system_comment: congress system user
congress_system_user_home: "/var/lib/{{ congress_system_user_name }}"
congress_config_options: "--config-file={{ congress_etc_dir }}/congress.conf --logfile /var/log/congress/{{ congress_program_name }}.log"
## Service Type and Data
congress_service_region: RegionOne
@ -135,3 +143,4 @@ congress_role_project_group: congress_all
## Tunable overrides
congress_congress_api_paste_ini_overrides: {}
congress_congress_conf_overrides: {}
congress_server_init_overrides: {}

View File

@ -16,10 +16,11 @@
- name: Stop services
service:
name: "{{ congress_program_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "started"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_congress_services }}"
register: _stop
until: _stop is success
retries: 5
@ -28,10 +29,11 @@
- name: Start services
service:
name: "{{ congress_program_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "started"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_congress_services }}"
register: _start
until: _start is success
retries: 5
@ -47,4 +49,3 @@
until: _wait_check is success
retries: 5
listen: "Restart congress services"

View File

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

View File

@ -1,52 +0,0 @@
---
# Copyright 2017, 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/{{ congress_program_name }}"
state: directory
owner: "{{ congress_system_user_name }}"
group: "{{ congress_system_group_name }}"
mode: "02755"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ congress_program_name }}"
state: directory
owner: "{{ congress_system_user_name }}"
group: "{{ congress_system_group_name }}"
mode: "02755"
- name: Create tmpfiles.d entry
template:
src: "congress-systemd-tmpfiles.j2"
dest: "/etc/tmpfiles.d/openstack-{{ congress_program_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
notify:
- Restart congress services
- name: Place the systemd init script
config_template:
src: "congress-systemd-init.j2"
dest: "/etc/systemd/system/{{ congress_program_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_type: "ini"
notify:
- Restart congress services

View File

@ -25,6 +25,18 @@
retries: 5
delay: 2
- name: Install developer distro packages
package:
name: "{{ congress_developer_mode_distro_packages }}"
state: "{{ congress_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: congress_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

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

View File

@ -38,9 +38,33 @@
tags:
- congress-config
- include: "congress_init_{{ ansible_service_mgr }}.yml"
- name: Run the systemd service role
include_role:
name: systemd_service
private: true
vars:
systemd_user_name: "{{ congress_system_user_name }}"
systemd_group_name: "{{ congress_system_group_name }}"
systemd_tempd_prefix: openstack
systemd_slice_name: congress
systemd_lock_path: /var/lock/congress
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_congress_services }}"
loop_control:
loop_var: service_var
tags:
- congress-config
- systemd-service
- include: congress_db_setup.yml
when:

View File

@ -1,31 +0,0 @@
# {{ ansible_managed }}
[Unit]
Description=congress openstack service
After=syslog.target
After=network.target
[Service]
Type=simple
User={{ congress_system_user_name }}
Group={{ congress_system_group_name }}
ExecStart={{ congress_bin }}/{{ congress_program_name }} {{ congress_config_options }}
ExecReload=/bin/kill -HUP $MAINPID
# 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=congress.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/{{ congress_program_name }} 2755 {{ congress_system_user_name }} {{ congress_system_group_name }}
D /var/run/{{ congress_program_name }} 2755 {{ congress_system_user_name }} {{ congress_system_group_name }}

View File

@ -13,6 +13,7 @@
# limitations under the License.
[DEFAULT]
use_journal = True
# Print more verbose output (set logging level to INFO instead of default WARNING level).
# Print debugging output (set logging level to DEBUG instead of default WARNING level).
@ -32,8 +33,6 @@
# syslog_log_facility = LOG_USER
# use_stderr = True
log_file = congress-server.log
log_dir = /var/log/congress
# publish_errors = False

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_congress_services: |-
{% set services = [] %}
{% for key, value in congress_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

@ -16,15 +16,21 @@
congress_distro_packages:
- git
- gcc
- python-dev
- python-antlr3
- libffi-dev
- libssl-dev
- libsystemd-dev
- libxml2
- libxslt1-dev
- libzip-dev
- build-essential
- build-essential
- libssl-dev
- libffi-dev
- python-antlr3
- python-dev
- python-setuptools
- python-mysqldb
- python-systemd
- python3-systemd
- pkg-config
congress_developer_mode_distro_packages:
- build-essential
- libsystemd-dev
- pkg-config