From 8c89d08980b5c13c6df7ebd71458598cb1424d5d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 13 Dec 2023 19:36:06 +0100 Subject: [PATCH] Integration of freezer to services. See https://chat.openai.com/share/c9f5587b-0a60-4005-9329-e53754e3fcfa --- group_vars/all | 9 +++++---- .../templates/backup-docker-to-local.service.j2 | 4 +++- .../templates/backup-remote-to-local.service.j2 | 2 ++ .../templates/cleanup-backups.service.j2 | 2 ++ .../templates/cleanup-disc-space.service.j2 | 4 +++- .../templates/cleanup-failed-docker-backups.service.j2 | 4 +++- roles/heal-docker/templates/heal-docker.service.j2 | 2 ++ roles/system-maintenance-service-freezer/tasks/main.yml | 4 ++-- .../system-maintenance-service-freezer.service.j2 | 2 +- roles/system-maintenance-service-freezer/vars/main.yml | 1 - roles/update-docker/templates/update-docker.service.j2 | 4 +++- 11 files changed, 26 insertions(+), 12 deletions(-) delete mode 100644 roles/system-maintenance-service-freezer/vars/main.yml diff --git a/group_vars/all b/group_vars/all index 2ffb0eb0..239265c6 100644 --- a/group_vars/all +++ b/group_vars/all @@ -26,10 +26,11 @@ size_percent_disc_space_warning: 85 size_percent_cleanup_disc_space: 90 # Path Variables -path_administrator_home: "/home/administrator/" -path_administrator_scripts: "{{path_administrator_home}}scripts/" -path_docker_volumes: "{{path_administrator_home}}volumes/docker/" -path_docker_compose_instances: "{{path_administrator_home}}docker-compose/" +path_administrator_home: "/home/administrator/" +path_administrator_scripts: "{{path_administrator_home}}scripts/" +path_docker_volumes: "{{path_administrator_home}}volumes/docker/" +path_docker_compose_instances: "{{path_administrator_home}}docker-compose/" +path_system_maintenance_service_freezer_script: "{{path_administrator_scripts}}system-maintenance-service-freezer.py" # Runtime Variables activate_all_timers: false # Activates all timers, independend if the handlers had been triggered diff --git a/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 b/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 index a1382dca..7b5af3f2 100644 --- a/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 +++ b/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service [Service] Type=oneshot -ExecStart=/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py \ No newline at end of file +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "backup-docker-to-local") | join(',') }}"' +ExecStart=/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file diff --git a/roles/backup-remote-to-local/templates/backup-remote-to-local.service.j2 b/roles/backup-remote-to-local/templates/backup-remote-to-local.service.j2 index 55a77ecc..8ba6faa3 100644 --- a/roles/backup-remote-to-local/templates/backup-remote-to-local.service.j2 +++ b/roles/backup-remote-to-local/templates/backup-remote-to-local.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service [Service] Type=oneshot +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "backup-remote-to-local") | join(',') }}"' ExecStart=/usr/bin/bash {{docker_backup_remote_to_local_folder}}backups-remote-to-local.sh +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' diff --git a/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 b/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 index cd900658..c9d979b9 100644 --- a/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 +++ b/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "cleanup-backups") | join(',') }}"' ExecStart=/usr/bin/python {{docker_cleanup_backups}}cleanup-backups.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}} +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file diff --git a/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 b/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 index afd1e27b..90536b3b 100644 --- a/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 +++ b/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot -ExecStart=/bin/bash {{cleanup_disc_space_folder}}cleanup-disc-space.sh {{size_percent_cleanup_disc_space}} \ No newline at end of file +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "cleanup-disc-space") | join(',') }}"' +ExecStart=/bin/bash {{cleanup_disc_space_folder}}cleanup-disc-space.sh {{size_percent_cleanup_disc_space}} +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file diff --git a/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.service.j2 b/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.service.j2 index c5c731e5..0c3f68de 100644 --- a/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.service.j2 +++ b/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot -ExecStart=/bin/sh -c '/usr/bin/yes | /usr/bin/bash {{backup_docker_to_local_cleanup_folder}}cleanup.sh {{backup_docker_to_local_cleanup_machine_id}} {{backup_docker_to_local_cleanup_trigger_directory}}' \ No newline at end of file +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "cleanup-failed-docker-backups") | join(',') }}"' +ExecStart=/bin/sh -c '/usr/bin/yes | /usr/bin/bash {{backup_docker_to_local_cleanup_folder}}cleanup.sh {{backup_docker_to_local_cleanup_machine_id}} {{backup_docker_to_local_cleanup_trigger_directory}}' +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file diff --git a/roles/heal-docker/templates/heal-docker.service.j2 b/roles/heal-docker/templates/heal-docker.service.j2 index 443d19a7..21b0e5dc 100644 --- a/roles/heal-docker/templates/heal-docker.service.j2 +++ b/roles/heal-docker/templates/heal-docker.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "heal-docker") | join(',') }}"' ExecStart=/bin/python {{heal_docker}}heal-docker.py +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file diff --git a/roles/system-maintenance-service-freezer/tasks/main.yml b/roles/system-maintenance-service-freezer/tasks/main.yml index eea7ab96..7eaf2e98 100644 --- a/roles/system-maintenance-service-freezer/tasks/main.yml +++ b/roles/system-maintenance-service-freezer/tasks/main.yml @@ -1,8 +1,8 @@ --- -- name: create {{freezer_script}} +- name: create {{path_system_maintenance_service_freezer_script}} copy: src: system-maintenance-service-freezer.py - dest: "{{freezer_script}}" + dest: "{{path_system_maintenance_service_freezer_script}}" - name: Configure system-maintenance-service for each action loop: diff --git a/roles/system-maintenance-service-freezer/templates/system-maintenance-service-freezer.service.j2 b/roles/system-maintenance-service-freezer/templates/system-maintenance-service-freezer.service.j2 index bde33184..3e821867 100644 --- a/roles/system-maintenance-service-freezer/templates/system-maintenance-service-freezer.service.j2 +++ b/roles/system-maintenance-service-freezer/templates/system-maintenance-service-freezer.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot -ExecStart=/bin/sh -c '/usr/bin/python {{ freezer_script }} {{item}} {{ system_maintenance_services | join(",") }}' \ No newline at end of file +ExecStart=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} {{item}} {{ system_maintenance_services | join(",") }}' \ No newline at end of file diff --git a/roles/system-maintenance-service-freezer/vars/main.yml b/roles/system-maintenance-service-freezer/vars/main.yml deleted file mode 100644 index 603baa23..00000000 --- a/roles/system-maintenance-service-freezer/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ -freezer_script: "{{path_administrator_scripts}}system-maintenance-service-freezer.py" diff --git a/roles/update-docker/templates/update-docker.service.j2 b/roles/update-docker/templates/update-docker.service.j2 index cbc1ba8c..6c75f722 100644 --- a/roles/update-docker/templates/update-docker.service.j2 +++ b/roles/update-docker/templates/update-docker.service.j2 @@ -4,4 +4,6 @@ OnFailure=systemd-notifier@%n.service [Service] Type=oneshot -ExecStart=/bin/sh -c '/usr/bin/python {{update_docker_script}} {{path_docker_compose_instances}}' \ No newline at end of file +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_maintenance_service_freezer_script }} freeze "{{ system_maintenance_services | reject('equalto', "update-docker") | join(',') }}"' +ExecStart=/bin/sh -c '/usr/bin/python {{update_docker_script}} {{path_docker_compose_instances}}' +ExecStartPost=/bin/sh -c 'systemctl start system-maintenance-service-defrost.service' \ No newline at end of file