initial changes and cleanup prior to service management code
This commit is contained in:
40
tasks/check_systemd_services.yml
Normal file
40
tasks/check_systemd_services.yml
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
- name: Verify Middleware Apache package presence
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: Capture a list of running services
|
||||
ansible.builtin.set_fact:
|
||||
bigboot_systemd_running_services:
|
||||
"{{ bigboot_systemd_running_services | default([]) + [item['key']] }}"
|
||||
loop: "{{ ansible_facts['services'] | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item['key'] }}"
|
||||
when:
|
||||
- "'running' in item['value']['state']"
|
||||
|
||||
- name: Get stop timeout value for running services
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
set -o pipefail
|
||||
systemctl show {{ item }} | grep TimeoutStopUSec
|
||||
changed_when: false
|
||||
register: bigboot_systemd_service_timeout
|
||||
loop: "{{ bigboot_systemd_running_services }}"
|
||||
|
||||
- name: Disable services exceeding the timeout threshold
|
||||
when:
|
||||
- item['item'] not in bigboot_protected_services
|
||||
- item['stdout'] | regex_replace('^.*=(.*$)', '\\1') | community.general.to_minutes > bigboot_service_max_timeout
|
||||
block:
|
||||
- name: Disabling services exceeding the timeout threshold
|
||||
ansible.builtin.include_tasks: tasks/disable_systemd_services.yml
|
||||
loop: "{{ bigboot_systemd_service_timeout['results'] }}"
|
||||
loop_control:
|
||||
label: "{{ item['item'] }}"
|
||||
|
||||
- name: Re-enabling services previously disabled
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop: "{{ bigboot_systemd_disabled_services }}"
|
11
tasks/disable_systemd_services.yml
Normal file
11
tasks/disable_systemd_services.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Disabling service for exceeding the timeout threshold
|
||||
ansible.builtin.service:
|
||||
name: "{{ item['item'] }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
|
||||
- name: Append service to list of disabled services
|
||||
ansible.builtin.set_fact:
|
||||
bigboot_systemd_disabled_services:
|
||||
"{{ bigboot_systemd_disabled_services | default([]) + [item['item']] }}"
|
Reference in New Issue
Block a user