From 6bc0ced3d83ea35eaee7b7ed879162393a98f703 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 18 Dec 2023 12:20:05 +0100 Subject: [PATCH] Added time trigger to clean up failed docker images at noon --- group_vars/all | 1 + roles/cleanup-failed-docker-backups/handlers/main.yml | 7 +++++++ roles/cleanup-failed-docker-backups/tasks/main.yml | 10 +++++++++- .../templates/cleanup-failed-docker-backups.timer.j2 | 10 ++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 diff --git a/group_vars/all b/group_vars/all index d6899768..2bf355b8 100644 --- a/group_vars/all +++ b/group_vars/all @@ -27,6 +27,7 @@ on_calendar_heal_docker: "*-*-* {{ hours_server_awake }}:30 on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00" # Renew Mailu certificates twice per day on_calendar_deploy_mailu_certificates: "*-*-* 13,01:30:00" # Deploy Mailu certificates twice per day on_calendar_msi_keyboard_color: "*-*-* *:*:00" # Change the keyboard color every minute +on_calendar_cleanup_failed_docker: "*-*-* 12:00:00" # Clean up failed docker backups every noon # Storage Space-Related Configurations diff --git a/roles/cleanup-failed-docker-backups/handlers/main.yml b/roles/cleanup-failed-docker-backups/handlers/main.yml index e22f29e5..cce18798 100644 --- a/roles/cleanup-failed-docker-backups/handlers/main.yml +++ b/roles/cleanup-failed-docker-backups/handlers/main.yml @@ -3,3 +3,10 @@ name: cleanup-failed-docker-backups.service enabled: yes daemon_reload: yes + +- name: "restart cleanup-failed-docker-backups.timer" + systemd: + name: cleanup-failed-docker-backups.timer + state: restarted + enabled: yes + daemon_reload: yes \ No newline at end of file diff --git a/roles/cleanup-failed-docker-backups/tasks/main.yml b/roles/cleanup-failed-docker-backups/tasks/main.yml index e525834a..69a761e5 100644 --- a/roles/cleanup-failed-docker-backups/tasks/main.yml +++ b/roles/cleanup-failed-docker-backups/tasks/main.yml @@ -22,4 +22,12 @@ - name: run the cleanup_failed_docker_backups tasks once set_fact: run_once_cleanup_failed_docker_backups: true - when: run_once_cleanup_failed_docker_backups is not defined \ No newline at end of file + when: run_once_cleanup_failed_docker_backups is not defined + +- name: create cleanup-failed-docker-backups.timer + template: + src: cleanup-failed-docker-backups.timer.j2 + dest: /etc/systemd/system/cleanup-failed-docker-backups.timer + register: cleanup_disc_space_timer + changed_when: cleanup_disc_space_timer.changed or activate_all_timers | bool + notify: restart cleanup-failed-docker-backups.timer \ No newline at end of file diff --git a/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 b/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 new file mode 100644 index 00000000..bcebf268 --- /dev/null +++ b/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=starts cleanup-failed-docker-backups.service + +[Timer] +OnCalendar={{on_calendar_cleanup_failed_docker}} +RandomizedDelaySec={{randomized_delay_sec}} +Persistent=true + +[Install] +WantedBy=timers.target