mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
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:
@@ -1,5 +0,0 @@
|
||||
- name: "reload sys-ctl-cln-disc-space service"
|
||||
systemd:
|
||||
name: sys-ctl-cln-disc-space{{ SYS_SERVICE_SUFFIX }}
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
14
roles/sys-ctl-cln-disc-space/tasks/01_core.yml
Normal file
14
roles/sys-ctl-cln-disc-space/tasks/01_core.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
- name: Include dependencies
|
||||
include_role:
|
||||
name: '{{ item }}'
|
||||
loop:
|
||||
- sys-ctl-alm-compose
|
||||
- sys-lock
|
||||
- sys-daemon
|
||||
-
|
||||
|
||||
- include_role:
|
||||
name: sys-systemctl
|
||||
vars:
|
||||
systemctl_timer_enabled: true
|
||||
systemctl_on_calendar: "{{SYS_SCHEDULE_CLEANUP_DISC_SPACE}}"
|
@@ -1,37 +1,5 @@
|
||||
- block:
|
||||
- name: Include dependencies
|
||||
include_role:
|
||||
name: '{{ item }}'
|
||||
loop:
|
||||
- sys-ctl-alm-compose
|
||||
- sys-lock
|
||||
- sys-rst-daemon
|
||||
- include_tasks: 01_core.yml
|
||||
- include_tasks: utils/run_once.yml
|
||||
when: run_once_sys_ctl_cln_disc_space is not defined
|
||||
|
||||
- name: "create {{cleanup_disc_space_folder}}"
|
||||
file:
|
||||
path: "{{cleanup_disc_space_folder}}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: create sys-ctl-cln-disc-space.sh
|
||||
template:
|
||||
src: sys-ctl-cln-disc-space.sh.j2
|
||||
dest: "{{cleanup_disc_space_folder}}sys-ctl-cln-disc-space.sh"
|
||||
|
||||
- name: create sys-ctl-cln-disc-space{{ SYS_SERVICE_SUFFIX }}
|
||||
template:
|
||||
src: sys-ctl-cln-disc-space.service.j2
|
||||
dest: /etc/systemd/system/sys-ctl-cln-disc-space{{ SYS_SERVICE_SUFFIX }}
|
||||
notify: reload sys-ctl-cln-disc-space service
|
||||
|
||||
- name: "set 'service_name' to '{{ role_name }}'"
|
||||
set_fact:
|
||||
service_name: "{{ role_name }}"
|
||||
|
||||
- name: "include role for sys-timer for {{ service_name }}"
|
||||
include_role:
|
||||
name: sys-timer
|
||||
vars:
|
||||
on_calendar: "{{SYS_SCHEDULE_CLEANUP_DISC_SPACE}}"
|
||||
|
@@ -14,7 +14,7 @@ for disc_use_percent in $(df --output=pcent | sed 1d)
|
||||
do
|
||||
disc_use_percent_number=$(echo "$disc_use_percent" | sed "s/%//")
|
||||
if [ "$disc_use_percent_number" -gt "$minimum_percent_cleanup_disc_space" ]; then
|
||||
echo "WARNING: $disc_use_percent_number exceeds the limit of {{size_percent_disc_space_warning}}%."
|
||||
echo "WARNING: $disc_use_percent_number exceeds the limit of {{SIZE_PERCENT_DISC_SPACE_WARNING}}%."
|
||||
force_freeing=true
|
||||
fi
|
||||
done
|
||||
@@ -22,9 +22,9 @@ if [ "$force_freeing" = true ]; then
|
||||
echo "cleaning up /tmp" &&
|
||||
find /tmp -type f -atime +10 -delete || exit 1
|
||||
|
||||
{% if backups_folder_path is defined and size_percent_maximum_backup is defined %}
|
||||
{% if BACKUPS_FOLDER_PATH is defined and SIZE_PERCENT_MAXIMUM_BACKUP is defined %}
|
||||
echo "cleaning up backups" &&
|
||||
python {{ PATH_ADMINISTRATOR_SCRIPTS }}sys-ctl-cln-backups/sys-ctl-cln-backups.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}} || exit 2
|
||||
python {{ PATH_ADMINISTRATOR_SCRIPTS }}sys-ctl-cln-backups/sys-ctl-cln-backups.py --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{SIZE_PERCENT_MAXIMUM_BACKUP}} || exit 2
|
||||
{% endif %}
|
||||
|
||||
if pacman -Qs $package > /dev/null ; then
|
@@ -1,8 +0,0 @@
|
||||
[Unit]
|
||||
Description=freeing disc space
|
||||
OnFailure=sys-ctl-alm-compose.{{ SOFTWARE_NAME }}@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{SYS_SERVICE_GROUP_CLEANUP| join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"'
|
||||
ExecStart=/bin/sh -c '/bin/bash {{cleanup_disc_space_folder}}sys-ctl-cln-disc-space.sh {{size_percent_cleanup_disc_space}}'
|
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=freeing disc space
|
||||
OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }}
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStartPre=/bin/sh -c '/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP| join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"'
|
||||
ExecStart=/bin/sh -c '/bin/bash {{ systemctl_id | get_service_script_path('sh') }} {{SIZE_PERCENT_CLEANUP_DISC_SPACE}}'
|
@@ -1 +1 @@
|
||||
cleanup_disc_space_folder: '{{ PATH_ADMINISTRATOR_SCRIPTS }}sys-ctl-cln-disc-space/'
|
||||
systemctl_id: "sys-ctl-cln-disc-space"
|
||||
|
Reference in New Issue
Block a user