Last active
August 29, 2015 14:02
-
-
Save vidul-nikolaev-petrov/7d842d36055190bce8f4 to your computer and use it in GitHub Desktop.
Restart Miner Rig On Failure
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
# Monitor and conditionally reboot the rig miner. | |
# (Uses `coldreboot` instead of `mine restart`.) | |
# Tested on SMOS 1.2. | |
# Start configuration. | |
# 1. name your cards and their minimal Mh/s | |
# 2. be sure to use the correct order, for instance: | |
# "Asus 1" is on the first PCIe x 16 slot | |
# "Asus 2" is on the second PCIe x 16 slot | |
# "Gigabyte 1" is on first PCIe x 1 slot | |
# "Gigabyte 1" is on second PCIe x 1 slot | |
# 3. Add a cron job: */5 * * * * /usr/sbin/check_rig.pl | |
my @cards = ( | |
["Asus 1", 400], | |
["Asus 2", 400], | |
["Gigabyte 1", 450], | |
["Gigabyte 2", 450], | |
); | |
# End configuration. | |
my $psminer = `ps -aef | grep -v grep | grep cgminer`; | |
my @stats = `/opt/bamt/getgpustat all hashrate`; | |
my $restart = '/sbin/coldreboot'; | |
my $logfile = '/opt/checkrig.log'; | |
my @data = (); | |
!$psminer && exit(0); | |
for (@stats) { | |
/(\d+)$/ && push(@data, $1); | |
} | |
$#data != $#cards && die "Invalid configuration!"; | |
for my $i (0 .. $#data) { | |
if ($data[$i] < $cards[$i][1]) { | |
write_to_log($logfile, | |
"'$cards[$i][0]' fault... restarting the rig:"); | |
`$restart`; | |
exit(0); | |
} | |
} | |
write_to_log($logfile, "ok, the rig is working fine:"); | |
sub write_to_log { | |
my $logfile = shift; | |
my $message = shift; | |
my $localtime = localtime; | |
open(my $fh, '>>', $logfile) or | |
die "cannot write to log file: $!"; | |
print $fh "$message $localtime\n"; | |
close($fh) or die $!; | |
} | |
__END__ | |
excerpt from the log file: | |
ok, the rig is working fine: Mon Jun 9 15:05:02 2014 | |
'Gigabyte 1' fault, restarting the rig: at Mon Jun 9 15:10:01 2014 | |
ok, the rig is working fine: Mon Jun 9 15:15:02 2014 | |
ok, the rig is working fine: Mon Jun 9 15:20:01 2014 | |
ok, the rig is working fine: Mon Jun 9 15:25:02 2014 | |
ok, the rig is working fine: Mon Jun 9 15:30:01 2014 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment