1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Read minicap pid from shell output. Should be more reliable for quick restarts.

This commit is contained in:
Simo Kinnunen 2015-07-21 15:34:58 +09:00
parent 76eb1b077a
commit 5a77d300dc

View file

@ -34,6 +34,7 @@ module.exports = syrup.serial()
this.desiredState = new StateQueue()
this.output = null
this.socket = null
this.pid = -1
this.banner = null
this.parser = null
this.frameConfig = config
@ -77,6 +78,9 @@ module.exports = syrup.serial()
.on('unexpectedEnd', this._outputEnded.bind(this))
return this._readOutput(this.output.stream)
})
.then(function() {
return this._waitForPid()
})
.then(function() {
return this._connectService()
})
@ -242,7 +246,28 @@ module.exports = syrup.serial()
return lifecycle.fatal()
}
var match
if ((match = /^PID: (\d+)$/.exec(line))) {
this.pid = +match[1]
this.emit('pid', this.pid)
}
log.info('minicap says: "%s"', line)
}.bind(this))
}
FrameProducer.prototype._waitForPid = function() {
if (this.pid > 0) {
return Promise.resolve(this.pid)
}
var pidListener
return new Promise(function(resolve/*, reject*/) {
this.on('pid', pidListener = resolve)
}.bind(this)).bind(this)
.timeout(2000)
.finally(function() {
this.removeListener('pid', pidListener)
})
}
@ -288,6 +313,7 @@ module.exports = syrup.serial()
.finally(function() {
this.output = null
this.socket = null
this.pid = -1
this.banner = null
this.parser = null
})
@ -323,7 +349,7 @@ module.exports = syrup.serial()
return Promise.resolve(true)
}
var pid = this.banner ? this.banner.pid : -1
var pid = this.pid
function kill(signal) {
if (pid <= 0) {