-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (73 loc) · 2.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const readline = require('readline')
const { spawn } = require('child_process')
const path = require('path')
const overclocking = require('./overclock')
const submissionInterval = parseInt(process.env.SUBMISSION_INTERVAL) || 60
const state = {}
let tOut = null
let miningProcess = null
function _overClock () {
overclocking.overclock({
core: process.env.OVERCLOCK_CORE,
mem: process.env.OVERCLOCK_MEM,
powerlimit: process.env.OVERCLOCK_POWERLIMIT,
fan: process.env.OVERCLOCK_FAN_PERCENT
})
}
exports.run = (sendError) => {
//
const farmRecheck = process.env.FARMRECHECK || 2000
let pars = [
'-G',
'-F', process.env.POOLADDRESS,
'--farm-recheck', farmRecheck,
'-v', '10'
]
if (process.env.BACKUP_POOLADDRESS) {
pars.push('-FS')
pars.push(process.env.BACKUP_POOLADDRESS)
}
if (process.env.CREDENTIALS) {
pars.push('-O')
pars.push(process.env.CREDENTIALS)
}
pars = process.env.MINER_PARS ? process.env.MINER_PARS.split(' ') : pars
const cmd = `${pars.join(' ')}`
function _run () {
console.log('running: ' + cmd)
miningProcess = spawn(path.join(__dirname, 'ethminer'), pars)
miningProcess.on('error', (err) => {
console.log(err)
})
miningProcess.stdout.pipe(process.stdout)
miningProcess.stderr.pipe(process.stderr)
const rl = readline.createInterface(miningProcess.stderr)
let n = 0
rl.on('line', function (line) {
const match = line.match(/([0-9]{1,}.[0-9]{1,})MH\/s/)
if (match) {
state.speed = parseFloat(match[1])
console.log(JSON.stringify(state))
if (state.speed > 0.1) {
n = 0
state.status = 'OK'
} else {
n += 1
}
if (state.speed < 0.1 && n > 30) {
state.status = 'FAILED'
console.log('killing mining process...')
miningProcess.kill()
setTimeout(() => _run(), 10000) // wait 10s
sendError(JSON.stringify(state))
}
}
})
}
setTimeout(() => _overClock(), 5000)
_run()
}
exports.statusHandler = (req, res, next) => {
res.json(state)
next()
}