Refactor systemctl services and timers

- Unified service templates into generic systemctl templates
- Introduced reusable filter plugins for script path handling
- Updated path variables and service/timer definitions
- Migrated roles (backup, cleanup, repair, etc.) to use systemctl role
- Added sys-daemon role for core systemd cleanup
- Simplified timer handling via sys-timer role

Note: This is a large refactor and some errors may still exist. Further testing and adjustments will be needed.
This commit is contained in:
2025-08-18 21:22:16 +02:00
parent 3a839cfe37
commit 2569abc0be
219 changed files with 618 additions and 1104 deletions

View File

@@ -0,0 +1,8 @@
- name: Include dependency 'sys-daemon'
include_role:
name: sys-daemon
when: run_once_sys_daemon is not defined
- name: "reset (if enabled)"
include_tasks: 02_reset.yml
when: MODE_RESET | bool

View File

@@ -1,4 +1,4 @@
- name: "pkgmgr install '{{ SYS_SERVICE_SUFFIX }}'"
- name: "pkgmgr install '{{ UNIT_SUFFIX_REMOVER_PACKAGE }}'"
include_role:
name: pkgmgr-install
vars:
@@ -6,7 +6,5 @@
- name: Remove all '{{ SYS_SERVICE_SUFFIX }}' files with '{{ UNIT_SUFFIX_REMOVER_PACKAGE }}'
command: "{{ UNIT_SUFFIX_REMOVER_PACKAGE }} -s '{{ SOFTWARE_NAME }}'"
- name: Reload systemd daemon
command: systemctl daemon-reload
become: true
notify: "reload system daemon"

View File

@@ -0,0 +1,28 @@
- name: "find best matching source for service script"
set_fact:
service_src: >-
{{
lookup('first_found', {
'files': [
'templates/script.sh.j2',
'templates/script.py.j2',
'files/script.sh',
'files/script.py'
]
}, errors='strict')
}}
when:
- systemctl_copy_files | bool
- name: "Load file logic for '{{ systemctl_id }}'"
include_tasks: 04_files.yml
when:
- systemctl_copy_files | bool
- service_src
- name: "Load systemctl logic for '{{ systemctl_id }}'"
include_tasks: 05_service.yml
- name: "Load timer logic for '{{ systemctl_id }}'"
include_tasks: 06_timer.yml
when: systemctl_timer_enabled | bool

View File

@@ -0,0 +1,23 @@
- name: "create {{ systemctl_script_dir }}"
file:
path: "{{ systemctl_script_dir }}"
state: directory
mode: "0755"
- name: "template or copy script"
block:
- name: "render template"
template:
src: "{{ service_src }}"
dest: "{{ [systemctl_script_dir, (service_src | basename | regex_replace('\\.j2$', ''))] | path_join }}"
mode: "0755"
when: service_src.endswith('.j2')
- name: "copy raw file"
copy:
src: "{{ service_src }}"
dest: "{{ [systemctl_script_dir, (service_src | basename)] | path_join }}"
mode: "0755"
when: not service_src.endswith('.j2')
when: systemctl_copy_files | bool

View File

@@ -0,0 +1,19 @@
- name: "setup systemctl {{ item }} '{{ systemctl_id }}'"
template:
src: "{{ lookup(
'first_found',
{
'files': ['templates/systemctl' ~ item ~ '.service.j2'],
'paths': [systemctl_role_dir, role_path]
},
errors='strict'
) }}"
dest: "{{ [ PATH_SYSTEM_SERVICE_DIR, systemctl_id ~ item ~ SYS_SERVICE_SUFFIX ] | path_join }}"
notify: "{{ 'reload system daemon' if item == '@' else 'refresh systemctl service' }}"
register: services_template
failed_when:
- services_template is failed
- "'Could not find or access' not in services_template.msg"
loop:
- ""
- "@"

View File

@@ -0,0 +1,6 @@
- set_fact:
systemctl_timer_service: "{{ systemctl_id }}"
- name: "include role for sys-timer for {{ systemctl_timer_service }}"
include_role:
name: sys-timer

View File

@@ -1,6 +1,14 @@
- block:
- name: "reset (if enabled)"
include_tasks: 01_reset.yml
when: MODE_RESET | bool
- include_tasks: 01_core.yml
- include_tasks: utils/run_once.yml
when: run_once_sys_systemctl is not defined
when: run_once_sys_systemctl is not defined
- name: "Execute service routines for '{{ systemctl_id }}'"
block:
- name: "Load base routine for '{{ systemctl_id }}'"
include_tasks: 03_base.yml
- include_tasks: utils/run_once.yml
vars:
# Necessary to flush after every service which uses an 'systemctl_id' otherwise wrong one will be used
flush_handlers: true
when: systemctl_id is defined