Monitor and repair your Rclone mounts (FStab) with Monit

This doc explain how to monitor a rclone mount present in fstab and repair it in case if it goes lazy.
Slack notification included :slight_smile:

apt install monit

copy and past this inside /etc/monit/conf.d/rclone

check directory rclone_pool_d path /mnt/rclone/pool_d
if does not exist then exec "/bin/bash -c '/usr/local/bin/ ; /bin/fusermount -uz /mnt/rclone/pool_d ; mount /mnt/rclone/pool_d'"

If mount go failed it send an alert to my slack channel thus unmount it (lazy fuse) and remount it. It must be present in fstab

Here is the code of the slack script:

URL=$(cat /etc/monit/slack-url)
COLOR=${MONIT_COLOR:-$([[ $MONIT_EVENT == "succeeded" ]] && echo good || echo danger)}
TEXT=$(echo -e "$MONIT_SERVICE - $MONIT_EVENT: $MONIT_DESCRIPTION" | python3 -c "import json,sys;print(json.dumps(")
"attachments": [
"text": $TEXT,
"color": "$COLOR",
"mrkdwn_in": ["text"],
"fields": [
{ "title": "Date", "value": "$MONIT_DATE", "short": true },
{ "title": "Host", "value": "$MONIT_HOST", "short": true }
curl -s -X POST --data-urlencode "payload=$PAYLOAD" $URL

systemctl enable monit
systemctl start monit

Monit Webview

Slack notification

Log of monit after an automatic remount


I keep wanting to check out monit but have not yet. Thanks a bunch for sharing!