Skip to content

Instantly share code, notes, and snippets.

@FredLackeyOfficial
Last active October 27, 2017 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FredLackeyOfficial/18cc50f80775206f5d94c7d5358b5572 to your computer and use it in GitHub Desktop.
Save FredLackeyOfficial/18cc50f80775206f5d94c7d5358b5572 to your computer and use it in GitHub Desktop.
Add Cron Job to Restart CGMiner Service Periodically

1. SSH Into Controller
Self explainatory.

2. Create Shell Script
Create the folder, the file...

mkdir /usr/share/cron/  
vi /usr/share/cron/cgrestart.sh  

The script is...

#!/bin/sh
# This file is for cron job

C=`pidof cgminer | wc -w`
if [ "$C" != "1" ]; then
    /etc/init.d/cgminer stop
/etc/init.d/cgminer start
exit 0;
fi

A=`cat /tmp/cm.log`
B=`cgminer-api  | grep "^   \[Accepted\]"`
echo $B > /tmp/cm.log
if [ "$A" == "$B" ]; then
    /etc/init.d/cgminer stop
    /etc/init.d/cgminer start
exit 0;
fi

3. Assign Execute Permissions to Script

chmod 755 /usr/share/cron/cgrestart.sh

4. Add the Script to CronTab
Edit contrab with the crontab -e command and add the following line:

0 */4 * * * /usr/share/cron/cgrestart.sh

This example will force a restart every 4 hours.

Note:
For more examples on CronTab settings, check out: CronTab.Guru

Optional: Setup Alerts
Receive alerts whenever your job fails to launch or complete. Create an alert at WDT.io and add the following suffix to the job in crontab:

&& wget -qT 30 http://k.wdt.io/%ACCOUNT_ID%/%ALERT_NAME%

Example:

&& wget -qT 30 http://k.wdt.io/71gd72ha/myalert01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment