Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active January 20, 2018 17:52
Show Gist options
  • Save bmatthewshea/6bad5242dbf270ef881c033918b947c0 to your computer and use it in GitHub Desktop.
Save bmatthewshea/6bad5242dbf270ef881c033918b947c0 to your computer and use it in GitHub Desktop.
BASH/CRONTAB - Restart ethminer service if stalled
#!/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
@bmatthewshea
Copy link
Author

bmatthewshea commented Oct 24, 2017

Please see: https://gist.github.com/bmatthewshea/9a062c092fd673318f8d208ce44f4f51 to run ethminer as a background service/daemon.

Make this executable (wherever you saved it):
sudo chmod 750 /opt/scripts/ethminer-monitor.sh
Add to root crontab & run every 15 mins:
sudo crontab -e
add:
0,15,30,45 * * * * /opt/scripts/ethminer-monitor.sh

@ddobreff
Copy link

You can always use monit to monitor pidfile :)

@bmatthewshea
Copy link
Author

bmatthewshea commented Nov 7, 2017

@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.

@bmatthewshea
Copy link
Author

Just updated it again - if using log area defined (/var/log/miners/*), you must first sudo 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'.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment