Browse Source

Convert systemd services to common role(s)

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: I54e3063d6e641a785377f9039641072f8001cf24
Dmitriy Rabotjagov 2 months ago
parent
commit
f3eddb3d51

+ 2
- 0
defaults/main.yml View File

@@ -169,11 +169,13 @@ gnocchi_services:
169 169
     service_name: "gnocchi-api"
170 170
     service_enabled: "{{ gnocchi_use_mod_wsgi | ternary(false, true) }}"
171 171
     init_config_overrides: "{{ gnocchi_api_init_overrides }}"
172
+    execstarts: "{{ gnocchi_bin }}/gnocchi-api"
172 173
   gnocchi-metricd:
173 174
     group: "gnocchi_metricd"
174 175
     service_name: "gnocchi-metricd"
175 176
     service_enabled: true
176 177
     init_config_overrides: "{{ gnocchi_metricd_init_overrides }}"
178
+    execstarts: "{{ gnocchi_bin }}/gnocchi-metricd"
177 179
 
178 180
 #: Common pip packages
179 181
 gnocchi_pip_packages:

+ 3
- 3
handlers/main.yml View File

@@ -18,7 +18,7 @@
18 18
     name: "{{ item.value.service_name }}"
19 19
     enabled: yes
20 20
     state: "stopped"
21
-    daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
21
+    daemon_reload: yes
22 22
   with_dict: "{{ gnocchi_services }}"
23 23
   when:
24 24
     - "item.value.group in group_names"
@@ -56,7 +56,7 @@
56 56
     name: "{{ item.value.service_name }}"
57 57
     enabled: yes
58 58
     state: "started"
59
-    daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
59
+    daemon_reload: yes
60 60
   with_dict: "{{ gnocchi_services }}"
61 61
   when:
62 62
     - "item.value.group in group_names"
@@ -74,7 +74,7 @@
74 74
     name: "{{ gnocchi_system_service_name }}"
75 75
     enabled: yes
76 76
     state: "restarted"
77
-    daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
77
+    daemon_reload: yes
78 78
   when: gnocchi_use_mod_wsgi | bool
79 79
   register: _restart
80 80
   until: _restart is success

+ 0
- 60
tasks/gnocchi_init_systemd.yml View File

@@ -1,60 +0,0 @@
1
----
2
-# Copyright 2016, Rackspace US, Inc.
3
-#
4
-# Licensed under the Apache License, Version 2.0 (the "License");
5
-# you may not use this file except in compliance with the License.
6
-# You may obtain a copy of the License at
7
-#
8
-#     http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-# Unless required by applicable law or agreed to in writing, software
11
-# distributed under the License is distributed on an "AS IS" BASIS,
12
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
-# See the License for the specific language governing permissions and
14
-# limitations under the License.
15
-
16
-- name: Create TEMP run dir
17
-  file:
18
-    path: "/var/run/{{ item.value.service_name }}"
19
-    state: directory
20
-    owner: "{{ gnocchi_system_user_name }}"
21
-    group: "{{ gnocchi_system_group_name }}"
22
-    mode: "02755"
23
-  with_dict: "{{ gnocchi_services }}"
24
-  when: "item.value.group in group_names"
25
-
26
-- name: Create TEMP lock dir
27
-  file:
28
-    path: "/var/lock/{{ item.value.service_name }}"
29
-    state: directory
30
-    owner: "{{ gnocchi_system_user_name }}"
31
-    group: "{{ gnocchi_system_group_name }}"
32
-    mode: "02755"
33
-  with_dict: "{{ gnocchi_services }}"
34
-  when: "item.value.group in group_names"
35
-
36
-- name: Create tmpfiles.d entry
37
-  template:
38
-    src: "gnocchi-systemd-tmpfiles.j2"
39
-    dest: "/etc/tmpfiles.d//{{ item.value.service_name }}.conf"
40
-    mode: "0644"
41
-    owner: "root"
42
-    group: "root"
43
-  with_dict: "{{ gnocchi_services }}"
44
-  when: "item.value.group in group_names"
45
-  notify:
46
-    - Restart gnocchi services
47
-
48
-- name: Place the systemd init script
49
-  config_template:
50
-    src: "gnocchi-systemd-init.j2"
51
-    dest: "/etc/systemd/system/{{ item.value.service_name }}.service"
52
-    mode: "0644"
53
-    owner: "root"
54
-    group: "root"
55
-    config_overrides: "{{ item.value.init_config_overrides }}"
56
-    config_type: "ini"
57
-  with_dict: "{{ gnocchi_services }}"
58
-  when: "item.value.group in group_names"
59
-  notify:
60
-    - Restart gnocchi services

+ 16
- 1
tasks/main.yml View File

@@ -38,10 +38,25 @@
38 38
   tags:
39 39
     - gnocchi-config
40 40
 
41
-- include_tasks: "gnocchi_init_{{ ansible_service_mgr }}.yml"
41
+- name: Run the systemd service role
42
+  include_role:
43
+    name: systemd_service
44
+    private: true
45
+  vars:
46
+    systemd_user_name: "{{ gnocchi_system_user_name }}"
47
+    systemd_group_name: "{{ gnocchi_system_group_name }}"
48
+    systemd_tempd_prefix: openstack
49
+    systemd_slice_name: gnocchi
50
+    systemd_lock_path: /var/lock/gnocchi
51
+    systemd_CPUAccounting: true
52
+    systemd_BlockIOAccounting: true
53
+    systemd_MemoryAccounting: true
54
+    systemd_TasksAccounting: true
55
+    systemd_services: "{{ filtered_gnocchi_services }}"
42 56
   when: not gnocchi_identity_only | bool
43 57
   tags:
44 58
     - gnocchi-config
59
+    - systemd-service
45 60
 
46 61
 - include_tasks: gnocchi_service_setup.yml
47 62
   when:

+ 0
- 30
templates/gnocchi-systemd-init.j2 View File

@@ -1,30 +0,0 @@
1
-# {{ ansible_managed }}
2
-
3
-[Unit]
4
-Description=gnocchi openstack service
5
-After=syslog.target
6
-After=network.target
7
-
8
-[Service]
9
-Type=simple
10
-User={{ gnocchi_system_user_name }}
11
-Group={{ gnocchi_system_group_name }}
12
-
13
-ExecStart={{ gnocchi_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/gnocchi/{{ item.value.service_name }}.log
14
-
15
-# Give a reasonable amount of time for the server to start up/shut down
16
-TimeoutSec=120
17
-Restart=on-failure
18
-RestartSec=2
19
-
20
-# This creates a specific slice which all services will operate from
21
-#  The accounting options give us the ability to see resource usage through
22
-#  the `systemd-cgtop` command.
23
-Slice=gnocchi.slice
24
-CPUAccounting=true
25
-BlockIOAccounting=true
26
-MemoryAccounting=false
27
-TasksAccounting=true
28
-
29
-[Install]
30
-WantedBy=multi-user.target

+ 0
- 4
templates/gnocchi-systemd-tmpfiles.j2 View File

@@ -1,4 +0,0 @@
1
-# {{ ansible_managed }}
2
-
3
-D /var/lock/{{ item.value.service_name }} 2755 {{ gnocchi_system_user_name }} {{ gnocchi_system_group_name }}
4
-D /var/run/{{ item.value.service_name }} 2755 {{ gnocchi_system_user_name }} {{ gnocchi_system_group_name }}

+ 25
- 0
vars/main.yml View File

@@ -23,3 +23,28 @@ gnocchi_api_paste_default_content: |
23 23
 gnocchi_policy_default_content: |
24 24
   {{ _git_file_fetch.results | selectattr('item', 'equalto', gnocchi_git_config_lookup_location ~ '/' ~ gnocchi_policy_git_file_path) | map(attribute='content') | first }}
25 25
 
26
+filtered_gnocchi_services: |-
27
+  {% set services = [] %}
28
+  {% for name, service in gnocchi_services.items() %}
29
+  {%   if (service['group'] in group_names) and
30
+          (('service_enabled' not in service) or
31
+           ('service_enabled' in service and service['service_enabled'])) %}
32
+  {%     set _ = service.update(
33
+           {
34
+             'service_key': name,
35
+             'enabled': 'yes',
36
+             'state': 'started',
37
+             'config_overrides': service.init_config_overrides
38
+           }
39
+         )
40
+  %}
41
+  {%     set _ = service.pop('init_config_overrides') -%}
42
+  {# Note (noonedeadpunk): The following if statement is added for backwards compatability #}
43
+  {# As up to stein release gnocchi role didn't have 'execstarts' in gnocchi_services keys #}
44
+  {%     if ('execstarts' not in service) %}
45
+  {%       set _ = service.update({'execstarts': gnocchi_bin ~ '/' ~ service.service_name}) %}
46
+  {%     endif %}
47
+  {%     set _ = services.append(service) %}
48
+  {%   endif %}
49
+  {% endfor %}
50
+  {{ services }}

Loading…
Cancel
Save