Skip to content

Instantly share code, notes, and snippets.

@alxcancado
Created May 4, 2018 18:20
Show Gist options
  • Save alxcancado/821e56e9d7b752ba4565f768197e8410 to your computer and use it in GitHub Desktop.
Save alxcancado/821e56e9d7b752ba4565f768197e8410 to your computer and use it in GitHub Desktop.
Checks for crashed ethOS mining processes
#!/bin/bash
LOG_FILE=/tmp/rigcheck.log
if grep -qv active /var/run/ethos/status.file; then
echo "$(date) Mining not active or currently starting, exiting..." | tee -a ${LOG_FILE}
exit 0
fi
NUM_PROC=`ps uax| egrep "ccminer|cgminer-skein|claymore|dstm-zcash|ethminer|ethminer-amd|ewbf-zcash|sgminer-gm|silentarmy|optiminer-zcash" | grep -v "curl" | grep -v "update-miner" | grep -v grep | awk '{print $2}' | wc -l`
NUM_GPU=`cat /var/run/ethos/gpulist.raw | wc -l`
NEEDS_RESTART=false
if [ "${NUM_PROC}" != "${NUM_GPU}" ]; then
echo "$(date) Number of GPU (${NUM_GPU}) differs from number of mining processes (${NUM_PROC})!" | tee -a ${LOG_FILE}
NEEDS_RESTART=true
fi
AGE_IN_MINUTES=3
for (( i = 0; i < ${NUM_GPU}; i++ ))
do
FILENAME=/var/run/miner.$i.output
IS_OLD=$(( (`date +%s` - `stat -L --format %Y ${FILENAME}`) > (${AGE_IN_MINUTES}*60) ))
if [ "${IS_OLD}" == "1" ]; then
NEEDS_RESTART=true
echo "$(date) Mining process log ${FILENAME} is older than ${AGE_IN_MINUTES} minutes!" | tee -a ${LOG_FILE}
fi
done
if [ "${NEEDS_RESTART}" == "true" ]; then
echo "$(date) Mining process crash detected, restarting mining processes..." | tee -a ${LOG_FILE}
/opt/ethos/bin/minestop
sleep 5
/opt/ethos/bin/minestart
echo "$(date) Done restarting mining processes!" | tee -a ${LOG_FILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment