feat(sys-service): migrate cleanup/backup services to generic units; harden disk-space cleanup

Services: add SYS_SERVICE_CLEANUP_BACKUPS and SYS_SERVICE_CLEANUP_DISC_SPACE in group vars.

sys-ctl-bkp-docker-2-loc: switch to sys-service; add ExecStartPre lock; ExecStartPost triggers backup cleanup; OnFailure → cleanup-failed; fix shell quoting.

sys-ctl-cln-bkps: switch to sys-service; pass CLI args via ExecStart; add ExecStartPre lock; set OnFailure; copy files; remove role-specific service template.

sys-ctl-cln-disc-space: switch to sys-service; enable timer; set OnFailure; provide ExecStart/ExecStartPre; copy files; remove role-specific service template.

script.sh (disc-space): non-interactive docker exec; consistent threshold message (use parameter); guard docker/pacman via command checks; robust container check; fix typo; use POSIX '='.

svc-opt-keyboard-color: minor formatting cleanup.

sys-ctl-hlth-disc-space: chain OnFailure to cleanup-disc-space service.

Context: ChatGPT conversation (Sep 10, 2025, Europe/Berlin) — https://chatgpt.com/share/68c1982e-bdc8-800f-bf13-a8b9f084f90e
This commit is contained in:
2025-09-10 17:24:56 +02:00
parent 79c623d8db
commit 91ce097a0a
10 changed files with 39 additions and 46 deletions

View File

@@ -6,7 +6,7 @@ minimum_percent_cleanup_disc_space="$1"
force_freeing=false
echo "Checking free disc space..."
df
if [ $# -gt 0 ] && [ "$2" == "--force" ]; then
if [ $# -gt 0 ] && [ "$2" = "--force" ]; then
echo "Forcing disc space freeing."
force_freeing=true
fi
@@ -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 ${minimum_percent_cleanup_disc_space}%."
force_freeing=true
fi
done
@@ -24,29 +24,31 @@ if [ "$force_freeing" = true ]; then
{% if BACKUPS_FOLDER_PATH is defined and SIZE_PERCENT_MAXIMUM_BACKUP is defined %}
echo "cleaning up backups" &&
python {{ 'sys-ctl-cln-bkps' | get_service_script_path('sh') }} --backups-folder-path {{ BACKUPS_FOLDER_PATH }} --maximum-backup-size-percent {{ SIZE_PERCENT_MAXIMUM_BACKUP }} || exit 2
systemctl start {{ SYS_SERVICE_CLEANUP_BACKUPS }} || exit 2
{% endif %}
if pacman -Qs $package > /dev/null ; then
if command -v docker >/dev/null 2>&1 ; then
echo "cleaning up docker" &&
docker system prune -f || exit 3
nextcloud_application_container="{{ applications | get_app_conf('web-app-nextcloud', 'docker.services.nextcloud.name', True) }}"
if [ "$(docker ps -a -q -f name=$nextcloud_application_container)" ] ; then
nextcloud_application_container="{{ applications | get_app_conf('web-app-nextcloud', 'docker.services.nextcloud.name') }}"
if [ -n "$nextcloud_application_container" ] && [ "$(docker ps -a -q -f name=$nextcloud_application_container)" ] ; then
echo "cleaning up docker nextcloud" &&
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ files:cleanup || exit 4
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ trashbin:cleanup --all-users || exit 5
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ versions:cleanup || exit 6
docker exec -u www-data $nextcloud_application_container /var/www/html/occ files:cleanup || exit 4
docker exec -u www-data $nextcloud_application_container /var/www/html/occ trashbin:cleanup --all-users || exit 5
docker exec -u www-data $nextcloud_application_container /var/www/html/occ versions:cleanup || exit 6
fi
fi
echo "cleaning pacman cache" &&
yes | pacman -Sc || exit 7
if command -v pacman >/dev/null 2>&1 ; then
echo "cleaning pacman cache" &&
yes | pacman -Sc || exit 7
fi
echo "cleanup finished."
else
echo "Sufficiend disc space available."
echo "Sufficient disc space available."
echo "To force the freeing of disc space pass the parameter --force."
fi
exit 0

View File

@@ -1,8 +0,0 @@
[Unit]
Description=freeing disc space
OnFailure={{ SYS_SERVICE_ON_FAILURE_COMPOSE }}
[Service]
Type=oneshot
ExecStartPre=/usr/bin/python {{ PATH_SYSTEM_LOCK_SCRIPT }} {{ SYS_SERVICE_GROUP_MANIPULATION | join(' ') }} --ignore {{ SYS_SERVICE_GROUP_CLEANUP | join(' ') }} --timeout "{{ SYS_TIMEOUT_BACKUP_SERVICES }}"
ExecStart={{ system_service_script_exec }} {{ SIZE_PERCENT_CLEANUP_DISC_SPACE }}