2019-06-15 23:02:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Find
|
|
|
|
drive=""
|
|
|
|
|
|
|
|
drive=$(cat /tmp/.mynode_drive)
|
|
|
|
while [ -z "$drive" ]; do
|
|
|
|
sleep 10
|
|
|
|
echo "Waiting on myNode Drive..."
|
|
|
|
drive=$(cat /tmp/.mynode_drive)
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Found Drive: $drive"
|
2022-03-16 04:40:19 +00:00
|
|
|
sleep 60s
|
2019-06-15 23:02:44 +00:00
|
|
|
|
|
|
|
lsblk $drive &> /dev/null
|
|
|
|
while [ $? -eq 0 ]; do
|
2020-09-09 02:29:39 +00:00
|
|
|
#echo "$drive still found..."
|
2021-01-28 04:01:34 +00:00
|
|
|
|
|
|
|
# Check drive usage
|
2021-02-04 01:11:19 +00:00
|
|
|
mb_available=$(df --block-size=M /mnt/hdd | grep /dev | awk '{print $4}' | cut -d'M' -f1)
|
|
|
|
if [ $mb_available -le 1000 ]; then
|
2022-03-16 04:40:19 +00:00
|
|
|
# Usage is 99.9%+, reboot to get into drive_full state with services stopped if first detected
|
2021-02-04 01:11:19 +00:00
|
|
|
echo "High Drive Usage: $mb_available MB available"
|
2022-03-16 04:40:19 +00:00
|
|
|
|
|
|
|
current_state=$(cat /tmp/.mynode_status)
|
|
|
|
if [ "$current_state" == "drive_full" ]; then
|
|
|
|
echo "Drive full already detected, not rebooting"
|
|
|
|
sleep 15m
|
|
|
|
else
|
|
|
|
echo "Just found drive full, rebooting..."
|
|
|
|
/usr/bin/mynode-reboot
|
|
|
|
fi
|
2021-01-28 04:01:34 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Wait, check again in one minute
|
2019-06-15 23:02:44 +00:00
|
|
|
sleep 60
|
|
|
|
lsblk $drive &> /dev/null
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Drive $drive NOT found! Rebooting."
|
|
|
|
reboot -f
|