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
@ddobreff - Yeah, that was something I mentioned in comments on Github (where I posted these gists). But for quick/dirty way - the log file modified time works well for me. Another problem is the binary tends to just 'stop' (and not die/become defunct/etc) when it does 'go down'. So 'watching' the console output AKA log file is a better method in this case. Till he 'defunct's' or exits process in source code on a network timeout(?) (my guess as to the halt condition), the PID method just wont work. It will continue to think binary is running - because it is.