Ethminerctl
Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
ToDo: Написать
#!/bin/bash
[ -z "${lowpower}" ] && lowpower='165'
[ -z "${highpower}" ] && highpower='175'
[ -z "${URL}" ] && URL="http://ethproxy.linuxoid.in:8880/$(hostname)"
ethpath='/home/rain/ethminer'
screensession="$(screen -ls | awk '/mainscreen/{print $1}')"
ownbin='/home/rain/bin'
cl='10000'
upsc='mustek600@192.168.222.254'
sayto() {
(cat - ; echo -n " on $(hostname)") | sendxmpp -t rain@jabberworld.info
}
showdate() {
echo -ne "\e[0;36m[\e[0;35m"$(date +%Y-%m-%d" "%H:%M:%S)"\e[0;36m]\e[0;0m "
}
case "${1}" in
start)
showdate
echo 'Starting ethminer'
echo -e '\n\n===== miner restart =====\n\n' >> /tmp/ethlog
${ownbin}/monit.sh lock
pkill monit.sh
pkill sgminer
while pidof sgminer 1>/dev/null
do
sleep 0.1
done
for i in $(seq 1 $(grep -c fglrx /etc/X11/xorg.conf))
do
DISPLAY=:0.$(($i-1)) aticonfig --pplib-cmd "set fanspeed 0 100" 1>/dev/null
done
screen -S "${screensession}" -X setenv ETHFLAGS "${ETHFLAGS}"
screen -S "${screensession}" -X setenv URL "${URL}"
screen -S "${screensession}" -X setenv lowpower "${lowpower}"
screen -S "${screensession}" -X setenv highpower "${highpower}"
screen -S "${screensession}" -X screen -t ethminer bash -c "$0 main"
;;
stop)
showdate
echo 'Stopping ethminer'
kill $(pidof ethminer)
;;
service)
find /home/rain/.ethash/ -maxdepth 1 -type f |
while read i
do
lsof -n /home/rain/.ethash/ | grep -q "$(basename "$i")" || rm -f "${i}"
done
mostmem="$(timeout 10 clinfo | awk '
BEGIN {
n=0
}
/CL_DEVICE_TYPE_GPU/{
g=1
}
/CL_DEVICE_TYPE_CPU/{
g=0
}
/Max memory/{
if (g==1) {
print $4" "n
n+=1
}
}' | sort -nr | awk '{
if (NF == 2 && NR == 1) print "--device "$2
}'
)"
screen -S "${screensession}" -X screen -t sgminer /bin/bash -c "/home/rain/currentminer/sgminer --config=/home/rain/config/pools.conf --lowmem -g 1 $mostmem"
while ! nc -w 1 -z localhost 4028
do
sleep 0.1
done
$ownbin/gpuoff 1>/dev/null
sync &
;;
lock)
touch /tmp/ethlock
;;
unlock)
rm -f /tmp/ethlock 2>/dev/null
;;
main)
LD_LIBRARY_PATH=${ethpath} ${ethpath}/ethminer --cl-local-work 256 ${ETHFLAGS} -G -v 9 -F ${URL} --disable-submit-hashrate 2>&1 |
tee -a /tmp/ethlog | gawk '
BEGIN {
fail=0
sol=0
rej=0
s=0
}
/Bailing/{
system("pkill -x ethminer ; '$0' notify Memory problem")
}
/FAILURE/{
fail+=1
rej=fail*100/sol
}
/Solution found/{
CONVFMT="%.2f"
sol+=1
rej=fail*100/sol
if (started!=1) {
system("'$0' service &")
started=1
}
shares[s]=systime()
s+=1
}
/gpuminer0.*workLoop 1/{
if (started!=1) {
n+=1
if (n>2) {
system("'$0' service &")
started=1
}
}
}
/Initialising miner/{
if (started==1) system("pkill -x ethminer ; '$0' notify New epoch restart")
}
{
OFMT="%.2f"
cnt=0
sum=0
for (l in shares) {
if (shares[l]>(systime()-1800)) cnt+=1
else shares[l]=""
}
printf "%-7s %-7s %-10s %s\n", "A:"sol, "R:"rej"%", "W:"cnt/30" s/m", "|"$0
nl+=1
if (nl>10) nl=0
if ($0 ~ /JSON/) arr[nl]=1
else arr[nl]=0
for (i in arr) sum+=arr[i]
if (sum*100/length(arr)>'50') {
system("pkill -x ethminer ; '$0' notify Connection problem")
sum=0
}
fflush()
}
'
date # process finish date
while [ "${cl}" != '0' ]
do
echo -ne "\rThis window will be automatically closed at ${cl} seconds (or press Enter) "
let cl-=1
read -t 1 && break
done
;;
notify)
shift
echo -n "$@" | sayto
;;
suspend)
showdate
echo 'Suspending ethminer'
pkill -SIGSTOP -x ethminer
;;
unsuspend)
showdate
echo 'Unsuspending ethminer'
pkill -SIGCONT -x ethminer
;;
monit)
while :;
do
[ -e '/tmp/ethlock' ] && { echo 'Script is locked' ; } || {
[ "0$(du /tmp/ethlog 2>/dev/null | awk '{print $1}')" -gt '10240' ] && {
sed '1,20000d' /tmp/ethlog > /tmp/ethlog.tmp && cat /tmp/ethlog.tmp > /tmp/ethlog
rm -f /tmp/ethlog.tmp 2>/dev/null
}
pgrep -x ethminer 1>/dev/null || $0 start &
tempalert="$(aticonfig --odgt --adapter=all | awk '/Temp/{n+=1 ; OFMT="%.f" ; t=$5+0 ; if (t>85) print n": "$0}')"
[ ! -z "${tempalert}" ] && { echo -n "${tempalert}" | sayto ; $0 suspend ; }
}
sleep 10
done
;;
power)
while :
do
data="$(upsc ${upsc} | awk '/input.voltage:/{OFMT="%.f" ; print $2+0}')"
[ ! -z "${data}" ] && {
[ "${data}" -le "${lowpower}" ] && {
[ ! -e '/tmp/lowpower' ] && {
showdate
echo "Low power: ${data}"
touch '/tmp/lowpower'
$0 suspend
$0 lock
}
}
[ "${data}" -gt "${highpower}" ] && {
[ -e '/tmp/lowpower' ] && {
showdate
echo "High power: ${data}"
$0 unlock
$0 unsuspend
rm -f '/tmp/lowpower' 2>/dev/null
}
}
}
sleep 10
done
;;
restart)
$0 lock
$0 stop
sleep 3
$0 start
$0 unlock
;;
*)
echo 'Tell me something...'
;;
esac