From 5caeb99c1d75acabe423a96d2e1660366ddaea5d Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Sun, 30 Jan 2022 13:22:47 +0100 Subject: [PATCH] created health check for btrfs --- playbook.yml | 5 +++++ roles/native-btrfs-health-check/README.md | 8 +++++++ .../files/btrfs-health-check.service | 8 +++++++ .../files/btrfs-health-check.sh | 6 +++++ .../files/btrfs-health-check.timer | 8 +++++++ .../handlers/main.yml | 12 ++++++++++ roles/native-btrfs-health-check/meta/main.yml | 2 ++ .../native-btrfs-health-check/tasks/main.yml | 22 +++++++++++++++++++ 8 files changed, 71 insertions(+) create mode 100644 roles/native-btrfs-health-check/README.md create mode 100644 roles/native-btrfs-health-check/files/btrfs-health-check.service create mode 100644 roles/native-btrfs-health-check/files/btrfs-health-check.sh create mode 100644 roles/native-btrfs-health-check/files/btrfs-health-check.timer create mode 100644 roles/native-btrfs-health-check/handlers/main.yml create mode 100644 roles/native-btrfs-health-check/meta/main.yml create mode 100644 roles/native-btrfs-health-check/tasks/main.yml diff --git a/playbook.yml b/playbook.yml index 42b4356b..90f0e378 100644 --- a/playbook.yml +++ b/playbook.yml @@ -7,6 +7,11 @@ - system-update - native-journalctl #- native-hostname +- name: setup btrfs health check + hosts: btrfs_health_check_hosts + become: true + roles: + - native-btrfs-health-check - name: setup standard wireguard hosts hosts: wireguard_hosts become: true diff --git a/roles/native-btrfs-health-check/README.md b/roles/native-btrfs-health-check/README.md new file mode 100644 index 00000000..1f888ba0 --- /dev/null +++ b/roles/native-btrfs-health-check/README.md @@ -0,0 +1,8 @@ +# btrfs-health-check + +Sends a health report + +## see +- https://superuser.com/questions/789303/how-to-monitor-btrfs-filesystem-raid-for-errors +- https://unix.stackexchange.com/questions/193619/list-all-btrfs-filesystems-and-subvolumes-in-shell +- https://www.freedesktop.org/software/systemd/man/systemd.unit.html diff --git a/roles/native-btrfs-health-check/files/btrfs-health-check.service b/roles/native-btrfs-health-check/files/btrfs-health-check.service new file mode 100644 index 00000000..23b65736 --- /dev/null +++ b/roles/native-btrfs-health-check/files/btrfs-health-check.service @@ -0,0 +1,8 @@ +[Unit] +Description=Check btrfs status +OnFailure=systemd-email@%n.service +OnSuccess=systemd-email@%n.service + +[Service] +Type=oneshot +ExecStart=/bin/bash /home/administrator/scripts/btrfs-health-check/btrfs-health-check.sh diff --git a/roles/native-btrfs-health-check/files/btrfs-health-check.sh b/roles/native-btrfs-health-check/files/btrfs-health-check.sh new file mode 100644 index 00000000..5a8b7a00 --- /dev/null +++ b/roles/native-btrfs-health-check/files/btrfs-health-check.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Checks the healt of all btrfs volumes +for path in $(btrfs filesystem show | awk '/ path /{print $NF}') +do + btrfs device stats $path +done diff --git a/roles/native-btrfs-health-check/files/btrfs-health-check.timer b/roles/native-btrfs-health-check/files/btrfs-health-check.timer new file mode 100644 index 00000000..9f116f74 --- /dev/null +++ b/roles/native-btrfs-health-check/files/btrfs-health-check.timer @@ -0,0 +1,8 @@ +[Unit] +Description=starts btrfs-health-check.service + +[Timer] +OnCalendar=12:00 + +[Install] +WantedBy=timers.target diff --git a/roles/native-btrfs-health-check/handlers/main.yml b/roles/native-btrfs-health-check/handlers/main.yml new file mode 100644 index 00000000..a6104905 --- /dev/null +++ b/roles/native-btrfs-health-check/handlers/main.yml @@ -0,0 +1,12 @@ +- name: "restart btrfs-health-check.service" + systemd: + name: btrfs-health-check.service + state: restarted + enabled: yes + daemon_reload: yes +- name: "restart btrfs-health-check.timer" + systemd: + name: btrfs-health-check.timer + state: restarted + enabled: yes + daemon_reload: yes diff --git a/roles/native-btrfs-health-check/meta/main.yml b/roles/native-btrfs-health-check/meta/main.yml new file mode 100644 index 00000000..9d9d34e2 --- /dev/null +++ b/roles/native-btrfs-health-check/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - native-systemd-email diff --git a/roles/native-btrfs-health-check/tasks/main.yml b/roles/native-btrfs-health-check/tasks/main.yml new file mode 100644 index 00000000..0e88f5ad --- /dev/null +++ b/roles/native-btrfs-health-check/tasks/main.yml @@ -0,0 +1,22 @@ +- name: "create /home/administrator/scripts/btrfs-health-check/" + file: + path: "/home/administrator/scripts/btrfs-health-check" + state: directory + mode: 0755 + +- name: create btrfs-health-check.sh + copy: + src: btrfs-health-check.sh + dest: "/home/administrator/scripts/btrfs-health-check/btrfs-health-check.sh" + +- name: create btrfs-health-check.service + copy: + src: btrfs-health-check.service + dest: "/etc/systemd/system/btrfs-health-check.service" + notify: restart btrfs-health-check.service + +- name: create btrfs-health-check.timer + copy: + src: btrfs-health-check.timer + dest: "/etc/systemd/system/btrfs-health-check.timer" + notify: restart btrfs-health-check.timer