RAID alerts for macOS Server

Although Apple’s Server app has an entry in the alerts section labelled ‘Disk’, it will not actually alert you of RAID failures even if that box is checked. It will only alert you if an entire volume is removed, but will not alert you if a RAID slice fails or is removed. Obviously, this is a major oversight as you need to be alerted whenever a RAID slice fails rather than having it silently sit there half-broken until it becomes completely broken… that defeats the purpose of most RAIDs.

I found a great script in a Stack Exchange comment. You can use the script to make macOS check the status of your RAIDs at least once a day and mail you if there is an issue.

Simply edit the script to put in your own email address and save it to /etc/periodic/daily/150.check-raid. Make sure you make the script executable by opening a Terminal and entering…

sudo chmod +x /etc/periodic/daily/150.check-raid

Now when macOS runs it’s daily maintenance scripts it will run this script as well and you’ll get an email if any of your RAIDs have a status that is anything other than ‘Online’. macOS will normally try to run maintenance at quiet times, such as overnight, but if you want to run it immediately to check just do…

sudo periodic daily

Copy of the script follows just in case anything ever happens to the earlier link…


# This script checks for any degraded/offline/failed/whatever software
# RAIDs, and if any are found emails a note to an admin. To use it,
# replace the ADMIN_EMAIL value with your own email address, drop it in
# /etc/periodic/daily, and change the owner to root. This'll make it
# run its check every morning at 3:15am.
# Warning: this script doesn't check anything other than software RAIDs
# built with the Apple (i.e. Disk Utility) RAID tools. It does not check
# any hardware RAIDs (including Apple's RAID card), or even any third-party
# software RAIDs. If "diskutil listraid" doesn't list it, it's not going
# to be checked.


if diskutil listraid | grep "^Status:" | grep -qv "Online$"; then
diskutil listraid | mail -s 'RAID problem detected' "$ADMIN_EMAIL"