Skip to content

Commit

Permalink
Merge pull request #32 from 71ae/ZIL-3
Browse files Browse the repository at this point in the history
Release v1.2
  • Loading branch information
71ae authored Aug 6, 2019
2 parents 4a34e23 + 5b8a492 commit a9f726e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 27 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You need to own a wallet address for ZIL.
Run the following commands in your ethOS shell:

```
bash <(curl -s https://raw.githubusercontent.com/71ae/crypto-zil-miner-switch-ethos/v1.1/install-zil.sh)
bash <(curl -s https://raw.githubusercontent.com/71ae/crypto-zil-miner-switch-ethos/v1.2/install-zil.sh)
```

### Configuration
Expand Down Expand Up @@ -82,7 +82,7 @@ rm zil-miner-switch/mineropts.txt

For upgrading just run the installer command again.
```
bash <(curl -s https://raw.githubusercontent.com/71ae/crypto-zil-miner-switch-ethos/v1.1/install-zil.sh)
bash <(curl -s https://raw.githubusercontent.com/71ae/crypto-zil-miner-switch-ethos/v1.2/install-zil.sh)
```

### Verification
Expand All @@ -99,12 +99,19 @@ are irrelevant):
18251 perl
```

Further more, to keep an eye on what these scripts actually are doing,
we're writing a tiny log file that you can tail with this command
(exit with `Ctrl-c`):
```
tail -f /tmp/zil-switch.log
```

If you are an experienced user, you may enter into the background screen:
```
screen -r zil
```
Make sure to exit this screen with `Ctrl-a d`. Do not keep it open for
longer than necessary, and do NOT do a `Ctrl-c`, as this likely would
longer than necessary, and do NOT do a `Ctrl-c` here as this likely would
stop the switcher.

### Farms
Expand Down
33 changes: 20 additions & 13 deletions src/zil-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/g

ZILLOOP="zil-loop"

case "$-" in
*i*)
INTERACTIVE=1
;;
*)
INTERACTIVE=0
;;
esac
LOG_FILE="/tmp/zil-switch.log"

# Clear Log
echo > $LOG_FILE

# Define Log Function
Log() {
msg="$*"
# print to the terminal if we have one
test -t 1 && echo "$(date "+%Y-%m-%d %H:%M:%S %Z") [$$] ""$msg"
# write to log file
echo "$(date "+%Y-%m-%d %H:%M:%S %Z") [$$] ""$msg" >> $LOG_FILE
}

# Start
Log "Starting ZIL Switcher."

for pid in $(pgrep -f ${ZILLOOP}.sh); do
if [ $pid != $$ ]; then
if [ "$INTERACTIVE" == "1" ]; then
echo "[$(date)]: ${ZILLOOP}.sh process is already running with PID $pid"
screen -ls | grep "zil"
fi
Log "${ZILLOOP}.sh process is already running with PID $pid."
test -t 1 && screen -ls | grep "zil"
test -t 1 && Log "Watch the log with: tail -f $LOG_FILE (Ctrl-c to stop)."
exit 1
fi
done


screen -wipe 2>&1 >/dev/null

Log "Entering ZIL Loop Screen"
screen -dmS zil -t zil ${HOME}/zil-miner-switch/${ZILLOOP}.sh

38 changes: 31 additions & 7 deletions src/zil-loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/ethos/bin:/opt/ethos/sbin"

LOG_FILE="/tmp/zil-switch.log"

# Define Log Function
Log() {
msg="$*"
# print to the terminal if we have one
test -t 1 && echo "$(date "+%Y-%m-%d %H:%M:%S %Z") [$$] ""$msg"
# write to log file
echo "$(date "+%Y-%m-%d %H:%M:%S %Z") [$$] ""$msg" >> $LOG_FILE
}

# Start
Log "Starting ZIL Switcher Loop."

# Make sure EthOS Miner is allowed for now
allow
Log "Allowing ethOS standard miner."
allow || Log "ERROR: allow"

# Loop forever
while :
Expand All @@ -13,33 +28,42 @@ do
for pid in $(pgrep -f $(basename $0)); do
status=$(ps ax | grep $pid | grep SCREEN)
if [[ -z $status ]] && [[ $pid != $$ ]]; then
echo "[$(date)]: Process is already running with PID $pid"
Log "Process is already running with PID $pid."
sleep 120
exit 1
fi
done

# Wait for Zilliqa ZIL PoW Time
perl ${HOME}/zil-miner-switch/zil-waitfor-pow.pl
Log "Wait for ZIL PoW Time"
perl ${HOME}/zil-miner-switch/zil-waitfor-pow.pl || \
Log "WARN: zil-waitfor-pow returned non-zero exit code."

# Stopp EthOS Miner
disallow
minestop
Log "Stopping ethOS default miner"
disallow || Log "ERROR: disallow"
minestop || Log "ERROR: minestop"

# Wait a few seconds
sleep 15

# Read config
Log "Reading ZIL Switcher Config"
source ${HOME}/zil-miner-switch/mineropts.txt
source ${HOME}/zil-miner-switch/minerpool.txt

# Start PhoenixMiner for ZIL Mining for 5 Minutes
/opt/miners/phoenixminer/PhoenixMiner -pool ${POOL} -wal ${WALLET} -worker ${HOSTNAME} -proto 2 -gsi 15 -log 1 -logfile /run/miner.output -rmode 0 -timeout 5 ${OPTS}
Log "Starting ZIL PhoenixMiner"
/opt/miners/phoenixminer/PhoenixMiner -pool ${POOL} -wal ${WALLET} -worker ${HOSTNAME} -proto 2 -gsi 15 -log 1 -logfile /run/miner.output -rmode 0 -timeout 5 ${OPTS} || \
Log "WARN: ZIL PhoenixMiner returned non-zero exit code."
Log "ZIL PhoenixMiner ended."

# Wait a few seconds
sleep 5

# Restart EthOS Miner
allow
Log "Allowing ethOS standard miner."
allow || Log "ERROR: allow"

# Repeat loop
done
Expand Down
31 changes: 27 additions & 4 deletions src/zil-waitfor-pow.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use LWP::Simple;
use JSON;
#use strict;
#use warnings;

# Initialize basics

Expand All @@ -19,19 +21,21 @@
my $powToGo = int(rand(100));
my $sleep = rand(60);
my $loop = 1;
my $logfile = "/tmp/zil-switch.log";

while ($loop) {

# Fetch blockchain info

my $ua = LWP::UserAgent->new;
$ua->agent("zilMinerSwitch/0." . 100-int($powToGo) . " (ethOS)");
$ua->agent("zilMinerSwitch/0." . (100-int($powToGo)) . " (ethOS)");
$ua->timeout(10);
my $res = $ua->request($req);

if ($res->is_error) {
print "ERROR $res->code: reading Zilliqa API ($res->message)\n";
&log("ERROR $res->code: reading Zilliqa API ($res->message)");
$sleep = $sleep * 0.7 - 0.1;
$currentBlock = "unknown";
}
else { # Decode result
my $json = $res->decoded_content . "\n";
Expand All @@ -41,16 +45,35 @@
$sleep = $powToGo * (rand(30)+50)/100 - 0.1;
}

print localtime(time) . ": ZIL $currentBlock / PoW $powToGo / " . int($sleep) . " mins \n";
&log(localtime(time) . ": ZIL $currentBlock / PoW $powToGo / " . (int($sleep)) . " mins");

if ( ($powToGo <= 1) or ($sleep < 0.3) ) {
$sleep = 0;
$loop = 0;
break;
last;
}

my $wait = $sleep * 60;
sleep $wait;

}


sub log {
my ($t) = @_;
eval {
open LOGFILE,">>$logfile" or die "Can't open logfile $logfile: $!";
my @l = qw/*STDOUT LOGFILE/;
for (@l) {
print $_ "$t\n" or die "Can't write LOG: $!";
}
close LOGFILE;
}
or do {
my $error = $@ || 'Unknown failure';
print "ERROR: ${error}";
sleep 120;
die "ERROR: $!";
}
}

0 comments on commit a9f726e

Please sign in to comment.