-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to send mail in case btrfs issues were detected
This can be very useful for smaller setups where the admin still would like to receive an email in case a disk in a btrfs RAID array fails. Partially resolves #88
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=Check for btrfs issues and send an email if any were found | ||
Documentation=man:btrfs | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/share/btrfsmaintenance/btrfs-errmail.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2022 Matthias Klumpp <[email protected]> | ||
|
||
umask 022 | ||
PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
export PATH | ||
|
||
if [ -f /etc/sysconfig/btrfsmaintenance ] ; then | ||
. /etc/sysconfig/btrfsmaintenance | ||
fi | ||
|
||
if [ -f /etc/default/btrfsmaintenance ] ; then | ||
. /etc/default/btrfsmaintenance | ||
fi | ||
|
||
. $(dirname $(realpath "$0"))/btrfsmaintenance-functions | ||
|
||
if [ -z "$BTRFS_MAILADDR" ] | ||
then | ||
# no email set, nothing to do for us | ||
exit 0 | ||
fi | ||
|
||
BTRFS_STATS_MOUNTPOINTS=$(expand_auto_mountpoint "auto") | ||
OIFS="$IFS" | ||
IFS=: | ||
for MM in $BTRFS_STATS_MOUNTPOINTS; do | ||
if ! is_btrfs "$MM"; then | ||
echo "Path $MM is not btrfs, skipping" | ||
continue | ||
fi | ||
devstats=$(btrfs device stats --check $MM 2>&1) | ||
if [ $? -ne 0 ]; then | ||
mail_body="$(sendmail -t <<EOF | ||
To: $BTRFS_MAILADDR | ||
Subject: Btrfs device issue on $MM @ $HOSTNAME | ||
This is an automatically generated mail message from btrfs-errmail | ||
running on $HOSTNAME | ||
An issue has been detected on the btrfs device mounted as $MM. | ||
Faithfully yours, etc. | ||
P.S. The 'btrfs device stats' output is: | ||
$devstats | ||
EOF | ||
)" | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=Check for btrfs issues and send mail if any were found | ||
Documentation=man:btrfs | ||
|
||
[Timer] | ||
OnCalendar=hourly | ||
Persistent=true | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters