mirror of
https://github.com/unraid/webgui.git
synced 2026-03-13 06:19:47 -05:00
Add more info to btrfs pools and more user friendly xfs repairs.
This commit is contained in:
@@ -1,28 +1,64 @@
|
||||
#!/bin/bash
|
||||
# btrfs_check start <dev> <id> <options>
|
||||
# btrfs_check start <dev> <id> <options>
|
||||
# btrfs_check status <dev> <id>
|
||||
# btrfs_check cancel <dev> <id>
|
||||
# btrfs_check reset <mountpoint>
|
||||
|
||||
# by default btrfs-check outputs to /var/lib/btrfs
|
||||
# By default btrfs-check outputs to /var/lib/btrfs
|
||||
mkdir -p /var/lib/btrfs
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
exec /sbin/btrfs check $4 $2 &> /var/lib/btrfs/check.status.$3 &
|
||||
# Start the btrfs check process in the background and log output
|
||||
/sbin/btrfs check $4 $2 &> /var/lib/btrfs/check.status.$3 &
|
||||
pid=$!
|
||||
echo $pid > /var/lib/btrfs/check.pid.$3
|
||||
exit 0
|
||||
;;
|
||||
'status')
|
||||
if [ -f /var/lib/btrfs/check.status.$3 ]; then
|
||||
cat /var/lib/btrfs/check.status.$3
|
||||
else
|
||||
echo "Not available"
|
||||
fi;
|
||||
# establish retval of this script: 0 running, 1 not running
|
||||
pgrep -f "/sbin/btrfs check .*$2" >/dev/null
|
||||
# Check if the process is running and set the return value accordingly
|
||||
if [ -f /var/lib/btrfs/check.pid.$3 ]; then
|
||||
cat /var/lib/btrfs/check.status.$3
|
||||
pid=$(cat /var/lib/btrfs/check.pid.$3)
|
||||
if kill -0 $pid 2>/dev/null; then
|
||||
# Process is running
|
||||
exit 9
|
||||
else
|
||||
if [ -f /var/lib/btrfs/check.status.$3 ]; then
|
||||
rm -f /var/lib/btrfs/check.pid.$3
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ -f /var/lib/btrfs/check.status.$3 ]; then
|
||||
cat /var/lib/btrfs/check.status.$3
|
||||
else
|
||||
echo "Not available"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
'cancel')
|
||||
pkill -f "/sbin/btrfs_check.*$2"
|
||||
while pgrep -f "/sbin/btrfs check .*$2" >/dev/null ; do
|
||||
sleep 1
|
||||
done
|
||||
echo "Cancelled" >> /var/lib/btrfs/check.status.$3
|
||||
# Cancel the btrfs check process
|
||||
if [ -f /var/lib/btrfs/check.pid.$3 ]; then
|
||||
pid=$(cat /var/lib/btrfs/check.pid.$3)
|
||||
kill $pid
|
||||
while kill -0 $pid 2>/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
echo -e "\nCancelled" >> /var/lib/btrfs/check.status.$3
|
||||
rm -f /var/lib/btrfs/check.pid.$3
|
||||
else
|
||||
echo "No process to cancel"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
'reset')
|
||||
exec /sbin/btrfs device stats -z $2
|
||||
;;
|
||||
*)
|
||||
echo "Invalid command"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,23 +1,100 @@
|
||||
#!/bin/bash
|
||||
# xfs_check start <dev> <id> <options>
|
||||
# xfs_check status <dev> <id>
|
||||
# xfs_check cancel <dev>
|
||||
# xfs_check cancel <dev>
|
||||
# xfs_check zero_log <dev>
|
||||
|
||||
# using /var/lib because that's where btrfs puts status
|
||||
# Exit codes:
|
||||
# 0 - No corruption detected or process not found.
|
||||
# 1 - Corruption detected.
|
||||
# 2 - Dirty log.
|
||||
# 4 - File system corruption fixed.
|
||||
# 8 - No check has been run yet.
|
||||
# 9 - Process is still running.
|
||||
|
||||
# Using /var/lib because that's where btrfs puts status
|
||||
mkdir -p /var/lib/xfs
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
exec /sbin/xfs_repair $4 $2 &> /var/lib/xfs/check.status.$3 &
|
||||
# Start the xfs_repair process in the background and log output
|
||||
nohup bash -c "(
|
||||
/sbin/xfs_repair $4 $2 &> /var/lib/xfs/check.status.$3
|
||||
echo \$? > /var/lib/xfs/check.status.$3.exit
|
||||
rm -f /var/lib/xfs/check.pid.$3
|
||||
) &" &
|
||||
pid=$!
|
||||
echo $pid > /var/lib/xfs/check.pid.$3
|
||||
exit 0
|
||||
;;
|
||||
'status')
|
||||
if [ -f /var/lib/xfs/check.status.$3 ]; then
|
||||
cat /var/lib/xfs/check.status.$3
|
||||
else
|
||||
echo "Not available"
|
||||
fi;
|
||||
pgrep -f "/sbin/xfs_repair.*$2" >/dev/null
|
||||
# Check if the process is still running
|
||||
if [ -f /var/lib/xfs/check.pid.$3 ]; then
|
||||
pid=$(cat /var/lib/xfs/check.pid.$3)
|
||||
if kill -0 $pid 2>/dev/null; then
|
||||
# Process is running, return status and exit code 9
|
||||
cat /var/lib/xfs/check.status.$3
|
||||
exit 9
|
||||
else
|
||||
# Process is not running, read the exit status if available
|
||||
if [ -f /var/lib/xfs/check.status.$3.exit ]; then
|
||||
exit_status=$(cat /var/lib/xfs/check.status.$3.exit)
|
||||
cat /var/lib/xfs/check.status.$3
|
||||
rm -f /var/lib/xfs/check.pid.$3
|
||||
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
|
||||
exit $exit_status
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
# Exit status file does not exist, but return status file if available
|
||||
if [ -f /var/lib/xfs/check.status.$3 ]; then
|
||||
cat /var/lib/xfs/check.status.$3
|
||||
fi
|
||||
exit 8
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# No PID file found, check for existing status
|
||||
if [ -f /var/lib/xfs/check.status.$3 ]; then
|
||||
cat /var/lib/xfs/check.status.$3
|
||||
# If no exit status file, assume process completed successfully
|
||||
if [ -f /var/lib/xfs/check.status.$3.exit ]; then
|
||||
exit_status=$(cat /var/lib/xfs/check.status.$3.exit)
|
||||
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
|
||||
exit $exit_status
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
exit 8
|
||||
fi
|
||||
else
|
||||
# No status file found
|
||||
echo "Not available"
|
||||
exit 8
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
'cancel')
|
||||
pkill -f "/sbin/xfs_repair.*$2"
|
||||
# Cancel the xfs_repair process
|
||||
if [ -f /var/lib/xfs/check.pid.$3 ]; then
|
||||
pid=$(cat /var/lib/xfs/check.pid.$3)
|
||||
kill $pid
|
||||
while kill -0 $pid 2>/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
echo -e "\nCancelled" >> /var/lib/xfs/check.status.$3
|
||||
rm -f /var/lib/xfs/check.pid.$3
|
||||
else
|
||||
echo "No process to cancel"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
# Handle invalid commands
|
||||
echo "Invalid command"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user