From b97018d84c57ea7da26d9daf01e4d1dd2f41d32d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 13 Dec 2023 21:14:08 +0100 Subject: [PATCH] Implemented freezer for docker --- playbook-common.yml => constructor.yml | 0 destructor.yml | 8 +++++++ playbook-pcs.yml => end_users.yml | 4 +++- group_vars/all | 2 ++ roles/backup-data-to-usb/meta/main.yml | 1 + roles/backup-docker-to-local/meta/main.yml | 3 ++- roles/backup-remote-to-local/meta/main.yml | 1 + roles/cleanup-backups-service/meta/main.yml | 1 + roles/cleanup-disc-space/meta/main.yml | 1 + .../meta/main.yml | 1 + roles/heal-docker/meta/main.yml | 2 ++ .../handlers/main.yml | 4 ++-- .../tasks/main.yml | 21 +++++++++++++++---- roles/update-docker/meta/main.yml | 2 ++ playbook-servers.yml => servers.yml | 4 +++- 15 files changed, 46 insertions(+), 9 deletions(-) rename playbook-common.yml => constructor.yml (100%) create mode 100644 destructor.yml rename playbook-pcs.yml => end_users.yml (96%) create mode 100644 roles/heal-docker/meta/main.yml create mode 100644 roles/update-docker/meta/main.yml rename playbook-servers.yml => servers.yml (98%) diff --git a/playbook-common.yml b/constructor.yml similarity index 100% rename from playbook-common.yml rename to constructor.yml diff --git a/destructor.yml b/destructor.yml new file mode 100644 index 00000000..1513f8ee --- /dev/null +++ b/destructor.yml @@ -0,0 +1,8 @@ +--- +- name: call destructor method + hosts: all + become: true + roles: + - role: system-maintenance-service-freezer + vars: + system_maintenance_service_freeze_action: "defrost" \ No newline at end of file diff --git a/playbook-pcs.yml b/end_users.yml similarity index 96% rename from playbook-pcs.yml rename to end_users.yml index cfe09714..8d3c0193 100644 --- a/playbook-pcs.yml +++ b/end_users.yml @@ -100,4 +100,6 @@ hosts: msi_perkeyrgb become: true roles: - - driver-msi-keyboard-color \ No newline at end of file + - driver-msi-keyboard-color + +- import_playbook: destructor.yml \ No newline at end of file diff --git a/group_vars/all b/group_vars/all index 239265c6..f366bf12 100644 --- a/group_vars/all +++ b/group_vars/all @@ -79,6 +79,8 @@ system_maintenance_services: - "heal-docker" - "update-docker" +system_maintenance_service_freeze_action: 'freeze' # Valid Values: freeze, defrost + # Routings redirect_domain_mappings: - { source: "nextcloud.{{top_domain}}", target: "cloud.{{top_domain}}" } diff --git a/roles/backup-data-to-usb/meta/main.yml b/roles/backup-data-to-usb/meta/main.yml index 3d2637ce..add533e5 100644 --- a/roles/backup-data-to-usb/meta/main.yml +++ b/roles/backup-data-to-usb/meta/main.yml @@ -1,3 +1,4 @@ --- dependencies: - role: cleanup-backups-service + - role: system-maintenance-service-freezer diff --git a/roles/backup-docker-to-local/meta/main.yml b/roles/backup-docker-to-local/meta/main.yml index cd0c75db..8bb53c96 100644 --- a/roles/backup-docker-to-local/meta/main.yml +++ b/roles/backup-docker-to-local/meta/main.yml @@ -2,4 +2,5 @@ dependencies: - git - backups-provider - systemd-notifier - - cleanup-failed-docker-backups \ No newline at end of file + - cleanup-failed-docker-backups + - system-maintenance-service-freezer \ No newline at end of file diff --git a/roles/backup-remote-to-local/meta/main.yml b/roles/backup-remote-to-local/meta/main.yml index 28fad1ec..634f4b04 100644 --- a/roles/backup-remote-to-local/meta/main.yml +++ b/roles/backup-remote-to-local/meta/main.yml @@ -3,3 +3,4 @@ dependencies: - systemd-notifier - cleanup-backups-timer - cleanup-failed-docker-backups + - system-maintenance-service-freezer diff --git a/roles/cleanup-backups-service/meta/main.yml b/roles/cleanup-backups-service/meta/main.yml index 89688f81..5553d6da 100644 --- a/roles/cleanup-backups-service/meta/main.yml +++ b/roles/cleanup-backups-service/meta/main.yml @@ -1,3 +1,4 @@ dependencies: - python-pip - systemd-notifier + - system-maintenance-service-freezer diff --git a/roles/cleanup-disc-space/meta/main.yml b/roles/cleanup-disc-space/meta/main.yml index 5c946b6c..8cfa9b66 100644 --- a/roles/cleanup-disc-space/meta/main.yml +++ b/roles/cleanup-disc-space/meta/main.yml @@ -1,2 +1,3 @@ dependencies: - systemd-notifier + - system-maintenance-service-freezer diff --git a/roles/cleanup-failed-docker-backups/meta/main.yml b/roles/cleanup-failed-docker-backups/meta/main.yml index 260ec638..dc05a8b0 100644 --- a/roles/cleanup-failed-docker-backups/meta/main.yml +++ b/roles/cleanup-failed-docker-backups/meta/main.yml @@ -1,3 +1,4 @@ dependencies: - git - systemd-notifier + - system-maintenance-service-freezer diff --git a/roles/heal-docker/meta/main.yml b/roles/heal-docker/meta/main.yml new file mode 100644 index 00000000..13944fb9 --- /dev/null +++ b/roles/heal-docker/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - system-maintenance-service-freezer diff --git a/roles/system-maintenance-service-freezer/handlers/main.yml b/roles/system-maintenance-service-freezer/handlers/main.yml index 8e92350b..c8d33c85 100644 --- a/roles/system-maintenance-service-freezer/handlers/main.yml +++ b/roles/system-maintenance-service-freezer/handlers/main.yml @@ -1,9 +1,9 @@ -- name: "restart system-maintenance-service-freeze.service" +- name: "reload system-maintenance-service-freeze.service" systemd: name: system-maintenance-service-freeze.service daemon_reload: yes -- name: "restart system-maintenance-service-defrost.service" +- name: "reload system-maintenance-service-defrost.service" systemd: name: system-maintenance-service-defrost.service daemon_reload: yes \ 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 7eaf2e98..d78a535e 100644 --- a/roles/system-maintenance-service-freezer/tasks/main.yml +++ b/roles/system-maintenance-service-freezer/tasks/main.yml @@ -3,6 +3,7 @@ copy: src: system-maintenance-service-freezer.py dest: "{{path_system_maintenance_service_freezer_script}}" + when: run_once_system_maintenance_service_freeze is not defined - name: Configure system-maintenance-service for each action loop: @@ -11,10 +12,22 @@ template: src: system-maintenance-service-freezer.service.j2 dest: "/etc/systemd/system/system-maintenance-service-{{ item }}.service" - notify: "restart system-maintenance-service-{{ item }} service" - when: run_once_systemd_freezer is not defined + notify: "reload system-maintenance-service-{{ item }} service" + when: run_once_system_maintenance_service_freeze is not defined - name: run the system_maintenance_service_freezer tasks once set_fact: - run_once_systemd_freezer: true - when: run_once_systemd_freezer is not defined \ No newline at end of file + run_once_system_maintenance_service_freeze: true + when: run_once_system_maintenance_service_freeze is not defined + +- name: "restart system-maintenance-service.service" + systemd: + name: system-maintenance-service-{{system_maintenance_service_freeze_action}}.service + state: restart + enabled: yes + daemon_reload: yes + when: maintenance_service_freeze_action_last is not defined or maintenance_service_freeze_action_last != system_maintenance_service_freeze_action + +- name: "set variable to prevent loading when action status didn't change" + set_fact: + maintenance_service_freeze_action_last: "{{system_maintenance_service_freeze_action}}" \ No newline at end of file diff --git a/roles/update-docker/meta/main.yml b/roles/update-docker/meta/main.yml new file mode 100644 index 00000000..13944fb9 --- /dev/null +++ b/roles/update-docker/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - system-maintenance-service-freezer diff --git a/playbook-servers.yml b/servers.yml similarity index 98% rename from playbook-servers.yml rename to servers.yml index 9cfcac7e..2e23f50c 100644 --- a/playbook-servers.yml +++ b/servers.yml @@ -1,6 +1,6 @@ --- -- import_playbook: playbook-common.yml +- import_playbook: constructor.yml - name: servers host setup hosts: servers @@ -241,3 +241,5 @@ roles: - role: nginx-www-redirect when: nginx_www_redirect | bool + +- import_playbook: destructor.yml