Use dictionary for service group mappings
Change the 'cloudkitty_service_names' from a list to a dictionary mapping of services, groups that install those services. This brings the method into line with that used in the os_neutron role in order to implement a more standardised method. The init tasks have been updated to run once and loop through this mapping rather than being included multiple times and re-run against each host. This may potentially reduce role run times. Currently the reload of upstart/systemd scripts may not happen if only one script changes as the task uses a loop with only one result register. This patch implements handlers to reload upstart/systemd scripts to ensure that this happens when any one of the scripts change. The handler to reload the services now only tries to restart the service if the host is in the group for the service according to the service group mapping. This allows us to ensure that handler failures are no longer ignored and that no execution time is wasted trying to restart services which do not exist on the host. Finally: - Common variables shared by each service's template files have been updated to use the service namespaced variables. - Unused handlers have been removed. - Unused variables have been removed. Change-Id: Ieb96fac62906ac9eb387edb450df0c0ca9c0ccb2
This commit is contained in:
11 changed files with 76 additions and 109 deletions
@@ -80,16 +80,19 @@ cloudkitty_service_adminuri: "{{ cloudkitty_service_adminuri_proto }}://{{ inter
cloudkitty_service_adminurl:"{{ cloudkitty_service_adminuri }}/"
cloudkitty_service_internaluri:"{{ cloudkitty_service_internaluri_proto }}://{{ internal_lb_vip_address }}:{{ cloudkitty_service_port }}"
cloudkitty_service_internalurl:"{{ cloudkitty_service_internaluri }}/"
cloudkitty_service_program_name:cloudkitty-api
cloudkitty_service_processor_program_name:cloudkitty-processor
cloudkitty_cloudkitty_conf_overrides:{}
cloudkitty_policy_overrides:{}
cloudkitty_api_paste_ini_overrides:{}
cloudkitty_service_names:
- cloudkitty-api
- cloudkitty-processor
## Service Name-Group Mapping
cloudkitty_services:
cloudkitty-api:
group:cloudkitty_api
service_name:cloudkitty-api
cloudkitty-processor:
group:cloudkitty_api
service_name:cloudkitty-processor
cloudkitty_pip_packages:
- cloudkitty
@@ -1,5 +1,5 @@
---
# Copyright 2014, Rackspace US, Inc.
# Copyright 2015, 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.
@@ -13,10 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name:Reload systemd daemon
command:"systemctl daemon-reload"
notify:
- Restart cloudkitty services
- name:Reload upstart init scripts
shell:|
initctl reload-configuration
notify:
- Restart cloudkitty services
- name:Restart cloudkitty services
service:
name:"{{ item }}"
state:restarted
pattern:"{{ item }}"
with_items:"{{ cloudkitty_service_names }}"
failed_when:false
name:"{{ item.value.service_name }}"
state:"restarted"
pattern:"{{ item.value.service_name }}"
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
@@ -1,34 +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.
- include:cloudkitty_init_common.yml
vars:
program_name:"{{ cloudkitty_service_program_name }}"
service_name:"{{ cloudkitty_service_name }}"
system_user:"{{ cloudkitty_system_user_name }}"
system_group:"{{ cloudkitty_system_group_name }}"
service_home:"{{ cloudkitty_system_home_folder }}"
when:>
inventory_hostname in groups['cloudkitty_api']
- include:cloudkitty_init_common.yml
vars:
program_name:"{{ cloudkitty_service_processor_program_name }}"
service_name:"{{ cloudkitty_service_name }}"
system_user:"{{ cloudkitty_system_user_name }}"
system_group:"{{ cloudkitty_system_group_name }}"
service_home:"{{ cloudkitty_system_home_folder }}"
when:>
inventory_hostname in groups['cloudkitty_api']
@@ -5,7 +5,7 @@
# 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
# 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,
@@ -23,7 +23,9 @@
- name:Load service
service:
name:"{{ program_name }}"
name:"{{ item.value.service_name }}"
enabled:"yes"
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services
@@ -15,19 +15,23 @@
- name:Create TEMP run dir
file:
path:"/var/run/{{ program_name }}"
path:"/var/run/{{ item.value.service_name }}"
state:directory
owner:"{{ system_user }}"
group:"{{ system_group }}"
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/{{ program_name }}"
path:"/var/lock/{{ item.value.service_name }}"
state:directory
owner:"{{ system_user }}"
group:"{{ system_group }}"
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:
@@ -36,18 +40,17 @@
mode:"0644"
owner:"root"
group:"root"
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
- name:Place the systemd init script
template:
src:"cloudkitty-systemd-init.j2"
dest:"/etc/systemd/system/{{ program_name }}.service"
dest:"/etc/systemd/system/{{ item.value.service_name }}.service"
mode:"0644"
owner:"root"
group:"root"
register:systemd_init
- name:Reload the systemd daemon
command:"systemctl daemon-reload"
when:systemd_init | changed
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services
- Reload systemd daemon
@@ -1,5 +1,5 @@
---
# Copyright 2016, Rackspace US, Inc.
# Copyright 2015, 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.
@@ -16,31 +16,11 @@
- name:Place the init script
template:
src:"cloudkitty-upstart-init.j2"
dest:"/etc/init/{{ program_name }}.conf"
dest:"/etc/init/{{ item.value.service_name }}.conf"
mode:"0644"
owner:"root"
group:"root"
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- name:Reload init scripts
shell:|
initctl reload-configuration
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- name:Load service
service:
name:"{{ program_name }}"
enabled:"yes"
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- Reload upstart init scripts
@@ -31,7 +31,7 @@
shell:"{{ cloudkitty_system_shell }}"
system:"yes"
createhome:"yes"
home:"/var/lib/{{ cloudkitty_system_user_name }}"
home:"{{ cloudkitty_system_home_folder }}"
tags:
- cloudkitty-user
@@ -48,7 +48,7 @@
- include:cloudkitty_db_setup.yml
when:inventory_hostname == groups['cloudkitty_all'][0]
- include:cloudkitty_init.yml
- include:cloudkitty_init_common.yml
- name:Flush handlers
meta:flush_handlers
@@ -7,13 +7,13 @@ After=network.target
[Service]
Type=simple
User={{ system_user }}
Group={{ system_group }}
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/{{ program_name }}.log
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ item.value.service_name }}.log
{% else %}
ExecStart={{ cloudkitty_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ program_name }}.log
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
@@ -1,4 +1,4 @@
# {{ ansible_managed }}
D /var/lock/{{ program_name }} 2755 {{ system_user }} {{ system_group }}
D /var/run/{{ program_name }} 2755 {{ system_user }} {{ system_group }}
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 }}
@@ -1,7 +1,8 @@
# {{ ansible_managed }}
description "{{ program_name }}"
author "Michae Rice <michael.rice@rackspace.com>"
description "{{ item.value.service_name }}"
author "Kevin Carter <kevin.carter@rackspace.com>"
start on runlevel [2345]
stop on runlevel [016]
@@ -10,33 +11,34 @@ respawn
respawn limit 10 5
# Set the RUNBIN environment variable
env RUNBIN="{{ cloudkitty_bin }}/{{ program_name }}"
env RUNBIN="{{ cloudkitty_bin }}/{{ item.value.service_name }}"
# Change directory to service users home
chdir "{{ service_home }}"
chdir "{{ cloudkitty_system_home_folder }}"
# Pre start actions
pre-start script
mkdir -p "/var/run/{{ program_name }}"
chown {{ system_user }}:{{ system_group }} "/var/run/{{ program_name }}"
mkdir -p "/var/run/{{ item.value.service_name }}"
chown {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "/var/run/{{ item.value.service_name }}"
mkdir -p "/var/lock/{{ program_name }}"
chown {{ system_user }}:{{ system_group }} "/var/lock/{{ program_name }}"
mkdir -p "/var/lock/{{ item.value.service_name }}"
chown {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "/var/lock/{{ item.value.service_name }}"
. {{ cloudkitty_bin }}/activate
. {{ cloudkitty_bin }}/activate
end script
# Post stop actions
post-stop script
rm "/var/run/{{ program_name }}/{{ program_name }}.pid"
rm "/var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid"
end script
# Run the start up job
exec start-stop-daemon --start \
--chuid {{ system_user }} \
--make-pidfile \
--pidfile /var/run/{{ program_name }}/{{ program_name }}.pid \
--exec "{{ program_override|default('$RUNBIN') }}" \
-- {{ program_config_options|default('') }} \
--log-file=/var/log/cloudkitty/{{ program_name }}.log
--chuid {{ cloudkitty_system_user_name }} \
--make-pidfile \
--pidfile /var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid \
--exec "{{ program_override|default('$RUNBIN') }}" \
-- {{ program_config_options|default('') }} \
--log-file=/var/log/{{ cloudkitty_service_name }}/{{ item.value.service_name }}.log
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.