From 4dfd382a7585ccc2e7f8f1b17c2d53107f1252c1 Mon Sep 17 00:00:00 2001 From: saibotk Date: Wed, 21 Feb 2024 22:25:46 +0100 Subject: [PATCH] feat(lvm_self_backup): Add error service when systemd service fails This is to be notified when the systemd service fails to e.g. unmount the partition. --- roles/lvm_self_backup/tasks/main.yml | 3 ++- roles/lvm_self_backup/templates/backup-error.service | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 roles/lvm_self_backup/templates/backup-error.service diff --git a/roles/lvm_self_backup/tasks/main.yml b/roles/lvm_self_backup/tasks/main.yml index a9640c2..7466d54 100644 --- a/roles/lvm_self_backup/tasks/main.yml +++ b/roles/lvm_self_backup/tasks/main.yml @@ -55,7 +55,7 @@ dest: "/usr/local/bin/backup-lvm-ls" become: true -- name: Install backup service & timer. +- name: Install backup services & timer. ansible.builtin.template: src: "{{ item }}" dest: /etc/systemd/system/ @@ -63,6 +63,7 @@ owner: "root" group: "root" with_items: + - "backup-error.service" - "backup-lvm.service" - "backup-lvm.timer" notify: Reload systemd config diff --git a/roles/lvm_self_backup/templates/backup-error.service b/roles/lvm_self_backup/templates/backup-error.service new file mode 100644 index 0000000..14e7dbe --- /dev/null +++ b/roles/lvm_self_backup/templates/backup-error.service @@ -0,0 +1,6 @@ +[Unit] +Description=Writes the error for the monitoring to pick the failure up. + +[Service] +Type=oneshot +ExecStart=/usr/bin/bash -c 'echo 1337 > {{ lvm_self_backup_status_directory }}/backup.status && chown {{ lvm_self_backup_status_directory_uid }}:{{ lvm_self_backup_status_directory_gid }} {{ lvm_self_backup_status_directory }}/backup.status'