Browse Source

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.

Change-Id: Id817631699d711993bbdad08660d8067550430e6
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
changes/70/587070/7
Kevin Carter 10 months ago
parent
commit
eac3740711

+ 20
- 8
defaults/main.yml View File

@@ -18,16 +18,30 @@ almanach_version: 4.0.9
18 18
 almanach_collector_program_name: almanach-collector
19 19
 almanach_api_program_name: almanach-api
20 20
 
21
-almanach_service_names:
22
-  - "almanach-api"
23
-  - "almanach-collector"
24
-
25
-almanach_requires_apt_packages:
26
-  - python3-pip
21
+almanach_venv_tag: untagged
22
+almanach_bin: "/openstack/venvs/almanach-{{ almanach_venv_tag }}/bin"
23
+
24
+almanach_services:
25
+  almanach-api:
26
+    group: almanach_all
27
+    service_name: almanach-api
28
+    init_config_overrides: "{{ almanach_api_init_config_overrides }}"
29
+    start_order: 1
30
+    execstarts: "{{ almanach_bin }}/almanach-api"
31
+  almanach-collector:
32
+    group: almanach_all
33
+    service_name: almanach-collector
34
+    init_config_overrides: "{{ almanach_collector_init_config_overrides }}"
35
+    start_order: 2
36
+    execstarts: "{{ almanach_bin }}/almanach-collector"
27 37
 
28 38
 almanach_requires_pip_packages:
29 39
   - virtualenv
30 40
 
41
+almanach_pip_packages:
42
+  - "almanach=={{ almanach_version }}"
43
+  - systemd-python
44
+
31 45
 almanach_system_user_name: almanach
32 46
 almanach_system_group_name: almanach
33 47
 almanach_system_shell: /bin/false
@@ -36,8 +50,6 @@ almanach_system_comment: almanach system user
36 50
 almanach_log_dir: /var/log/almanach
37 51
 almanach_log_file: /var/log/almanach/almanach.log
38 52
 
39
-almanach_app_dir: /opt/almanach
40
-
41 53
 almanach_config_dir: /etc/almanach
42 54
 almanach_config_file: /etc/almanach/almanach.conf
43 55
 almanach_logrotate_config_file: /etc/logrotate.d/almanach

+ 2
- 2
handlers/main.yml View File

@@ -26,7 +26,7 @@
26 26
 
27 27
 - name: Restart almanach services
28 28
   systemd:
29
-    name: "{{ item }}"
29
+    name: "{{ item.service_name }}"
30 30
     state: "restarted"
31
-  with_items: "{{ almanach_service_names }}"
31
+  with_items: "{{ filtered_almanach_services }}"
32 32
   failed_when: false

+ 0
- 30
tasks/almanach_init.yml View File

@@ -1,30 +0,0 @@
1
----
2
-# Copyright 2016, Internap 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
-- include: almanach_init_systemd.yml
17
-  vars:
18
-    program_name: "{{ almanach_api_program_name }}"
19
-    service_name: "almanach-api"
20
-    system_user: "{{ almanach_system_user_name }}"
21
-    system_group: "{{ almanach_system_group_name }}"
22
-    init_config_overrides: "{{ almanach_api_init_config_overrides }}"
23
-
24
-- include: almanach_init_systemd.yml
25
-  vars:
26
-    program_name: "{{ almanach_collector_program_name }}"
27
-    service_name: "almanach-collector"
28
-    system_user: "{{ almanach_system_user_name }}"
29
-    system_group: "{{ almanach_system_group_name }}"
30
-    init_config_overrides: "{{ almanach_collector_init_config_overrides }}"

+ 0
- 24
tasks/almanach_init_systemd.yml View File

@@ -1,24 +0,0 @@
1
----
2
-# Copyright 2016, Internap 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: Place the systemd init script
17
-  template:
18
-    src: "almanach-systemd-init.j2"
19
-    dest: "/etc/systemd/system/{{ program_name }}.service"
20
-    mode: "0644"
21
-    owner: "root"
22
-    group: "root"
23
-  notify:
24
-    - Restart almanach services

+ 32
- 7
tasks/almanach_install.yml View File

@@ -13,20 +13,45 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
-- name: Update APT index
17
-  apt: update_cache=yes
18
-  become: True
19
-
20 16
 - name: Install apt packages
21
-  apt:
17
+  package:
22 18
     name: "{{ almanach_requires_apt_packages | join(' ') }}"
23 19
     state: present
20
+    update_cache: yes
21
+  register: install_packages
22
+  until: install_packages is success
23
+  retries: 5
24
+  delay: 2
25
+
26
+# NOTE(cloudnull): This role has no "developer_mode" as such the developer
27
+#                  packages are simply installed.
28
+- name: Install developer apt packages
29
+  package:
30
+    name: "{{ almanach_developer_mode_distro_packages }}"
31
+    state: present
32
+    update_cache: yes
33
+  register: install_packages
34
+  until: install_packages is success
35
+  retries: 5
36
+  delay: 2
24 37
 
25 38
 - name: Install pip packages
26 39
   pip:
27 40
     name: "{{ almanach_requires_pip_packages }}"
28 41
     state: present
29 42
     executable: pip3
43
+  register: install_packages
44
+  until: install_packages is success
45
+  retries: 5
46
+  delay: 2
30 47
 
31
-- name: Install Almanach
32
-  pip: name=almanach version={{ almanach_version }} virtualenv={{ almanach_app_dir }} virtualenv_python=python3
48
+- name: Install pip packages
49
+  pip:
50
+    name: "{{ almanach_pip_packages }}"
51
+    state: present
52
+    virtualenv: "/openstack/venvs/almanach-{{ almanach_venv_tag }}"
53
+    virtualenv_python: "python3"
54
+  register: install_packages
55
+  until: install_packages is success
56
+  retries: 5
57
+  delay: 2

+ 26
- 15
tasks/main.yml View File

@@ -24,19 +24,6 @@
24 24
   tags:
25 25
     - always
26 26
 
27
-- name: Check init system
28
-  command: cat /proc/1/comm
29
-  changed_when: false
30
-  register: _pid1_name
31
-  tags:
32
-    - always
33
-
34
-- name: Set the name of pid1
35
-  set_fact:
36
-    pid1_name: "{{ _pid1_name.stdout }}"
37
-  tags:
38
-    - always
39
-
40 27
 - include: almanach_pre_install.yml
41 28
   tags:
42 29
     - almanach-install
@@ -50,6 +37,30 @@
50 37
     - almanach-install
51 38
     - almanach-config
52 39
 
53
-- include: almanach_init.yml
40
+- name: Run the systemd service role
41
+  include_role:
42
+    name: systemd_service
43
+    private: true
44
+  vars:
45
+    systemd_user_name: "{{ almanach_system_user_name }}"
46
+    systemd_group_name: "{{ almanach_system_group_name }}"
47
+    systemd_tempd_prefix: openstack
48
+    systemd_slice_name: almanach
49
+    systemd_lock_path: /var/lock/almanach
50
+    systemd_CPUAccounting: true
51
+    systemd_BlockIOAccounting: true
52
+    systemd_MemoryAccounting: true
53
+    systemd_TasksAccounting: true
54
+    systemd_services:
55
+      - service_name: "{{ service_var.service_name }}"
56
+        enabled: yes
57
+        state: started
58
+        execstarts: "{{ service_var.execstarts }}"
59
+        execreloads: "{{ service_var.execreloads | default([]) }}"
60
+        config_overrides: "{{ service_var.init_config_overrides }}"
61
+  with_items: "{{ filtered_almanach_services }}"
62
+  loop_control:
63
+    loop_var: service_var
54 64
   tags:
55
-    - almanach-install
65
+    - almanach-config
66
+    - systemd-service

+ 0
- 31
templates/almanach-systemd-init.j2 View File

@@ -1,31 +0,0 @@
1
-# {{ ansible_managed }}
2
-
3
-[Unit]
4
-Description=Almanach api openstack service
5
-After=syslog.target
6
-After=network.target
7
-
8
-[Service]
9
-Type=simple
10
-EnvironmentFile=/etc/environment
11
-User={{ system_user }}
12
-Group={{ system_group }}
13
-
14
-ExecStart={{ almanach_app_dir }}/bin/{{ program_name }} --config-file={{ almanach_config_file }} --log-file={{ almanach_log_file }}
15
-
16
-# Give a reasonable amount of time for the server to start up/shut down
17
-TimeoutSec=120
18
-Restart=on-failure
19
-RestartSec=2
20
-
21
-# This creates a specific slice which all services will operate from
22
-#  The accounting options give us the ability to see resource usage through
23
-#  the `systemd-cgtop` command.
24
-Slice=almanach.slice
25
-CPUAccounting=true
26
-BlockIOAccounting=true
27
-MemoryAccounting=false
28
-TasksAccounting=true
29
-
30
-[Install]
31
-WantedBy=multi-user.target

+ 1
- 0
templates/almanach.conf.j2 View File

@@ -1,4 +1,5 @@
1 1
 [DEFAULT]
2
+use_journal = True
2 3
 
3 4
 [api]
4 5
 bind_ip = {{ almanach_bind_ip }}

+ 31
- 0
vars/main.yml View File

@@ -0,0 +1,31 @@
1
+---
2
+# Copyright 2018, 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
+#
17
+# Compile a list of the services on a host based on whether
18
+# the host is in the host group and the service is enabled.
19
+# The service list is provided in the defined start order.
20
+#
21
+filtered_almanach_services: |-
22
+  {% set services = [] %}
23
+  {% for key, value in almanach_services.items() %}
24
+  {%   if (value['group'] in group_names) and
25
+          (('condition' not in value) or
26
+           ('condition' in value and value['condition'])) %}
27
+  {%     set _ = value.update({'service_key': key}) %}
28
+  {%     set _ = services.append(value) %}
29
+  {%   endif %}
30
+  {% endfor %}
31
+  {{ services | sort(attribute='start_order') }}

+ 0
- 17
vars/ubuntu-14.04.yml View File

@@ -1,17 +0,0 @@
1
----
2
-# Copyright 2016, Internap 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
-## APT Cache options
17
-cache_timeout: 600

+ 8
- 0
vars/ubuntu-16.04.yml View File

@@ -15,3 +15,11 @@
15 15
 
16 16
 ## APT Cache options
17 17
 cache_timeout: 600
18
+
19
+almanach_requires_apt_packages:
20
+  - python3-pip
21
+
22
+almanach_developer_mode_distro_packages:
23
+  - build-essential
24
+  - libsystemd-dev
25
+  - pkg-config

Loading…
Cancel
Save