Last active
January 20, 2018 17:52
-
-
Save bmatthewshea/6bad5242dbf270ef881c033918b947c0 to your computer and use it in GitHub Desktop.
BASH/CRONTAB - Restart ethminer service if stalled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH=$PATH:/usr/bin:/usr/sbin:/var/log/miners:/home/ubuntu/scripts | |
SECS=$(date +%s) | |
ETHMINERLOGFILE=/var/log/miners/ethminer.log | |
ETHMINERRESTART=/var/log/miners/ethminer-restarts.log | |
idletime=$(expr $SECS - $(date +%s -r $ETHMINERLOGFILE)) | |
echo -n "$(date) - Status check running.. " &>> $ETHMINERRESTART | |
if [ "$idletime" -gt 300 ] | |
then | |
echo "$(date) - ETHMINER process has been idle for: $idletime seconds" &>> $ETHMINERRESTART | |
echo "$(date) - Restarting..." &>> $ETHMINERRESTART | |
echo "Last 20 lines of old log:" &>> $ETHMINERRESTART | |
echo "" &>> $ETHMINERRESTART | |
/usr/bin/tail -n 20 $ETHMINERLOGFILE >> $ETHMINERRESTART | |
service ethminer restart | |
else | |
echo "OK" &>> $ETHMINERRESTART | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just updated it again - if using log area defined (
/var/log/miners/*
), you must firstsudo mkdir /var/log/miners
and then own it to user running daemon. Example:sudo chown -R ubuntu:adm /var/log/miners
if running service as user 'ubuntu'.