Skip to content

Instantly share code, notes, and snippets.

@sxd
Created December 15, 2015 19:50
Show Gist options
  • Save sxd/c0012f27811718e0a034 to your computer and use it in GitHub Desktop.
Save sxd/c0012f27811718e0a034 to your computer and use it in GitHub Desktop.
#!/bin.sh
# We get all de scrubs
function get_pg_scrub_dates {
ceph pg dump | awk '$1 ~ /[0-9a-f]+\.[0-9a-f]+/ {print $22, $23, $1}' | sort > /tmp/scrub_dates
}
# We start running the dep scrub
function run_deep_scrub {
# We should check the return :P
ceph pg deep-scrub $1
}
function check_scrubbing {
ceph status | grep scrubbing
if [ $? -eq 1 ]; then
return 0
else
return 1
fi
}
function check_scrub_dates {
echo $1
NOW=`date +"%s"`
DATE=`date -d "$1" +"%s"`
DIFF=`expr $NOW - $DATE`
if [ $DIFF -gt 84600 ]; then
return 0
else
return 1
fi
}
# We start reading the dates
function read_pg_dates {
date=`head -1 /tmp/scrub_dates | awk '{print $1}'`
apg=`head -1 /tmp/scrub_dates | awk '{print $3}'`
check_scrub_dates $date
date_ok=$?
echo $date_ok
if [ $date_ok -eq 0 ]; then
run_deep_scrub ${apg}
fi
if [ $date_ok -eq 1 ]; then
return 1
fi
}
# Should we still running ?
function still_running {
date=`head -1 /tmp/scrub_dates | awk '{print $1}'`
NOW=`date +"%s"`
DATE=`date -d "$5" +"%s"`
DIFF=`expr $NOW - $DATE`
if [ $DIFF -gt 4320 ]; then
return 0
else
return 1
fi
}
function start_daemon {
while [ 1 ]; do
check_scrubbing
if [ $? -eq 0 ]; then
read_pg_dates
fi
get_pg_scrub_dates
still_running
if [ $? -eq 1 ]; then
exit 0
fi
sleep 120
done
}
get_pg_scrub_dates
start_daemon &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment