From ef8a0925b6a1044e052373c48e7699b7b9961665 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 10 Jan 2024 23:36:18 +0100 Subject: [PATCH] Optimized handlers and variable names --- group_vars/all | 9 +++++---- .../backup-docker-to-local-everything.service.j2 | 2 +- .../templates/backup-docker-to-local.service.j2 | 2 +- .../templates/backup-remote-to-local.service.j2 | 2 +- .../templates/cleanup-backups.service.j2 | 2 +- .../templates/cleanup-disc-space.service.j2 | 2 +- .../templates/cleanup-failed-docker-backups.service.j2 | 2 +- roles/heal-docker/templates/heal-docker.service.j2 | 2 +- roles/system-storage-optimizer/handlers/main.yml | 5 +++++ roles/system-storage-optimizer/tasks/main.yml | 1 + .../templates/system-storage-optimizer.service.j2 | 2 +- roles/update-docker/templates/update-docker.service.j2 | 2 +- 12 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 roles/system-storage-optimizer/handlers/main.yml diff --git a/group_vars/all b/group_vars/all index e7779984..bd286c48 100644 --- a/group_vars/all +++ b/group_vars/all @@ -68,10 +68,11 @@ nginx_matomo_tracking: false # Activates matomo tracking on all html pa # System maintenance Services ## Timeouts to wait for other services to stop -sytem_maintenance_lock_timeoutcleanup_services: "15min" -sytem_maintenance_lock_timeoutbackup_services: "1h" -sytem_maintenance_lock_timeoutheal_docker: "30min" -sytem_maintenance_lock_timeoutupdate_docker: "2min" +sytem_maintenance_lock_timeout_cleanup_services: "15min" +sytem_maintenance_lock_timeout_storage_optimizer: "10min" +sytem_maintenance_lock_timeout_backup_services: "1h" +sytem_maintenance_lock_timeout_heal_docker: "30min" +sytem_maintenance_lock_timeout_update_docker: "2min" ## Services diff --git a/roles/backup-docker-to-local/templates/backup-docker-to-local-everything.service.j2 b/roles/backup-docker-to-local/templates/backup-docker-to-local-everything.service.j2 index 1634b531..e6806af4 100644 --- a/roles/backup-docker-to-local/templates/backup-docker-to-local-everything.service.j2 +++ b/roles/backup-docker-to-local/templates/backup-docker-to-local-everything.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service cleanup-failed-docker-backups.cymai [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py --everything' \ No newline at end of file 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 2ef790c4..cdeba0f1 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,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service cleanup-failed-docker-backups.cymai [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local-everything') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local-everything') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py' \ 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 b7600535..89a454fa 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,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service cleanup-failed-docker-backups.cymai [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_backup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_backup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/usr/bin/bash {{docker_backup_remote_to_local_folder}}backups-remote-to-local.sh' diff --git a/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 b/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 index 11d534a7..418b4e7f 100644 --- a/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 +++ b/roles/cleanup-backups-service/templates/cleanup-backups.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/usr/bin/python {{docker_cleanup_backups}}cleanup-backups.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}}' \ 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 20106966..66c4e28f 100644 --- a/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 +++ b/roles/cleanup-disc-space/templates/cleanup-disc-space.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/bin/bash {{cleanup_disc_space_folder}}cleanup-disc-space.sh {{size_percent_cleanup_disc_space}}' \ 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 5efd90ed..e8858ec6 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,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"' ExecStart=/bin/sh -c '/usr/bin/yes | /usr/bin/bash {{backup_docker_to_local_cleanup_folder}}cleanup-all.sh {{backup_docker_to_local_cleanup_trigger_directory}}' \ 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 784191c7..2eb816c3 100644 --- a/roles/heal-docker/templates/heal-docker.service.j2 +++ b/roles/heal-docker/templates/heal-docker.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} heal-docker --timeout "{{sytem_maintenance_lock_timeoutheal_docker}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services| join(' ') }} heal-docker --timeout "{{sytem_maintenance_lock_timeout_heal_docker}}"' ExecStart=/bin/sh -c '/bin/python {{heal_docker}}heal-docker.py' \ No newline at end of file diff --git a/roles/system-storage-optimizer/handlers/main.yml b/roles/system-storage-optimizer/handlers/main.yml new file mode 100644 index 00000000..439e7244 --- /dev/null +++ b/roles/system-storage-optimizer/handlers/main.yml @@ -0,0 +1,5 @@ +- name: "reload system-storage-optimizer.cymais.service" + systemd: + name: system-storage-optimizer.cymais.service + state: reloaded + daemon_reload: yes diff --git a/roles/system-storage-optimizer/tasks/main.yml b/roles/system-storage-optimizer/tasks/main.yml index aca01bfd..f7fc9c34 100644 --- a/roles/system-storage-optimizer/tasks/main.yml +++ b/roles/system-storage-optimizer/tasks/main.yml @@ -8,6 +8,7 @@ template: src: system-storage-optimizer.service.j2 dest: /etc/systemd/system/system-storage-optimizer.cymais.service + notify: reload system-storage-optimizer.cymais.service - name: create system-storage-optimizer.py copy: diff --git a/roles/system-storage-optimizer/templates/system-storage-optimizer.service.j2 b/roles/system-storage-optimizer/templates/system-storage-optimizer.service.j2 index a65a5981..ca1dbeba 100644 --- a/roles/system-storage-optimizer/templates/system-storage-optimizer.service.j2 +++ b/roles/system-storage-optimizer/templates/system-storage-optimizer.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore system-storage-optimizer backup-remote-to-local' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore system-storage-optimizer backup-remote-to-local --timeout "{{sytem_maintenance_lock_timeout_storage_optimizer}}"' ExecStart=/bin/sh -c '/usr/bin/python {{storage_optimizer_script}} --rapid-storage-path {{path_rapid_storage}} --mass-storage-path {{path_mass_storage}}' \ No newline at end of file diff --git a/roles/update-docker/templates/update-docker.service.j2 b/roles/update-docker/templates/update-docker.service.j2 index 9935691b..1f102218 100644 --- a/roles/update-docker/templates/update-docker.service.j2 +++ b/roles/update-docker/templates/update-docker.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier.cymais@%n.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services | join(' ') }} update-docker --timeout "{{sytem_maintenance_lock_timeoutheal_docker}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_cleanup_services | join(' ') }} update-docker --timeout "{{sytem_maintenance_lock_timeout_heal_docker}}"' ExecStart=/bin/sh -c '/usr/bin/python {{update_docker_script}} {{path_docker_compose_instances}}' \ No newline at end of file