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
@@ -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.