created health check for btrfs

This commit is contained in:
Kevin Veen-Birkenbach 2022-01-30 13:22:47 +01:00
parent 3b30832e60
commit 5caeb99c1d
8 changed files with 71 additions and 0 deletions

View File

@ -7,6 +7,11 @@
- system-update - system-update
- native-journalctl - native-journalctl
#- native-hostname #- native-hostname
- name: setup btrfs health check
hosts: btrfs_health_check_hosts
become: true
roles:
- native-btrfs-health-check
- name: setup standard wireguard hosts - name: setup standard wireguard hosts
hosts: wireguard_hosts hosts: wireguard_hosts
become: true become: true

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,8 @@
[Unit]
Description=starts btrfs-health-check.service
[Timer]
OnCalendar=12:00
[Install]
WantedBy=timers.target

View File

@ -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

View File

@ -0,0 +1,2 @@
dependencies:
- native-systemd-email

View File

@ -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