From 8e269821d382cab6dbb8aecc1898e76b2f232b5a Mon Sep 17 00:00:00 2001 From: Julian Rother Date: Sat, 16 Sep 2023 19:39:55 +0200 Subject: [PATCH] Use flock locking in services --- defaults/main.yml | 3 +++ templates/backup-check.service.j2 | 2 +- templates/backup-retention.service.j2 | 2 +- templates/backup-run.service.j2 | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 7e66df3..76a27dc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,12 +3,15 @@ backups: retention: enabled: true OnCalendar: "1:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}" + lock_timeout: "{{ 6*60*60 }}" run: enabled: true OnCalendar: "3,11,19:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}" + lock_timeout: "{{ 6*60*60 }}" check: enabled: true OnCalendar: "monday 5:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}" + lock_timeout: "{{ 6*60*60 }}" export: enabled: false OnCalendar: "{{ [21,22,23]|random(seed=(inventory_hostname + 'backups_export_h')) }}:{{ 60|random(seed=(inventory_hostname + 'backups_export_m')) }}" diff --git a/templates/backup-check.service.j2 b/templates/backup-check.service.j2 index 9f1dfb3..75fd992 100644 --- a/templates/backup-check.service.j2 +++ b/templates/backup-check.service.j2 @@ -6,5 +6,5 @@ OnFailure=status-email-root@%n.service Nice=19 IOSchedulingClass=idle Type=simple -ExecStart=/usr/local/bin/backup-check +ExecStart=/bin/flock --timeout {{ backups.jobs.check.lock_timeout }} /run/backup-client.flock /usr/local/bin/backup-check diff --git a/templates/backup-retention.service.j2 b/templates/backup-retention.service.j2 index 1900494..1be1496 100644 --- a/templates/backup-retention.service.j2 +++ b/templates/backup-retention.service.j2 @@ -6,5 +6,5 @@ OnFailure=status-email-root@%n.service Nice=19 IOSchedulingClass=idle Type=simple -ExecStart=/usr/local/bin/backup-retention +ExecStart=/bin/flock --timeout {{ backups.jobs.retention.lock_timeout }} /run/backup-client.flock /usr/local/bin/backup-retention diff --git a/templates/backup-run.service.j2 b/templates/backup-run.service.j2 index 9f277f4..aa78eb7 100644 --- a/templates/backup-run.service.j2 +++ b/templates/backup-run.service.j2 @@ -6,5 +6,5 @@ OnFailure=status-email-root@%n.service Nice=19 IOSchedulingClass=idle Type=simple -ExecStart=/usr/local/bin/backup-full +ExecStart=/bin/flock --timeout {{ backups.jobs.run.lock_timeout }} /run/backup-client.flock /usr/local/bin/backup-full