mirror of
https://github.com/openstf/stf
synced 2025-10-03 17:59:28 +02:00
Shut down stf local in proper order so that the console doesn't get ugly.
This commit is contained in:
parent
78b768406a
commit
aec95d87a4
2 changed files with 130 additions and 95 deletions
170
lib/cli.js
170
lib/cli.js
|
@ -459,96 +459,102 @@ program
|
|||
var log = logger.createLogger('cli')
|
||||
, options = cliutil.lastArg(arguments)
|
||||
|
||||
// app triproxy
|
||||
procutil.fork(__filename, [
|
||||
'triproxy', 'app001'
|
||||
, '--bind-pub', options.bindAppPub
|
||||
, '--bind-dealer', options.bindAppDealer
|
||||
, '--bind-pull', options.bindAppPull
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('app triproxy died', err.stack)
|
||||
})
|
||||
var procs = [
|
||||
// app triproxy
|
||||
procutil.fork(__filename, [
|
||||
'triproxy', 'app001'
|
||||
, '--bind-pub', options.bindAppPub
|
||||
, '--bind-dealer', options.bindAppDealer
|
||||
, '--bind-pull', options.bindAppPull
|
||||
])
|
||||
|
||||
// device triproxy
|
||||
procutil.fork(__filename, [
|
||||
'triproxy', 'dev001'
|
||||
, '--bind-pub', options.bindDevPub
|
||||
, '--bind-dealer', options.bindDevDealer
|
||||
, '--bind-pull', options.bindDevPull
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('device triproxy died', err.stack)
|
||||
})
|
||||
// device triproxy
|
||||
, procutil.fork(__filename, [
|
||||
'triproxy', 'dev001'
|
||||
, '--bind-pub', options.bindDevPub
|
||||
, '--bind-dealer', options.bindDevDealer
|
||||
, '--bind-pull', options.bindDevPull
|
||||
])
|
||||
|
||||
// processor one
|
||||
procutil.fork(__filename, [
|
||||
'processor', 'proc001'
|
||||
, '--connect-app-dealer', options.bindAppDealer
|
||||
, '--connect-dev-dealer', options.bindDevDealer
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('processor 001 died', err.stack)
|
||||
})
|
||||
// processor one
|
||||
, procutil.fork(__filename, [
|
||||
'processor', 'proc001'
|
||||
, '--connect-app-dealer', options.bindAppDealer
|
||||
, '--connect-dev-dealer', options.bindDevDealer
|
||||
])
|
||||
|
||||
// processor two
|
||||
procutil.fork(__filename, [
|
||||
'processor', 'proc002'
|
||||
, '--connect-app-dealer', options.bindAppDealer
|
||||
, '--connect-dev-dealer', options.bindDevDealer
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('processor 002 died', err.stack)
|
||||
})
|
||||
// processor two
|
||||
, procutil.fork(__filename, [
|
||||
'processor', 'proc002'
|
||||
, '--connect-app-dealer', options.bindAppDealer
|
||||
, '--connect-dev-dealer', options.bindDevDealer
|
||||
])
|
||||
|
||||
// reaper one
|
||||
procutil.fork(__filename, [
|
||||
'reaper', 'reaper001'
|
||||
, '--connect-push', options.bindDevPull
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('reaper 001 died', err.stack)
|
||||
})
|
||||
// reaper one
|
||||
, procutil.fork(__filename, [
|
||||
'reaper', 'reaper001'
|
||||
, '--connect-push', options.bindDevPull
|
||||
])
|
||||
|
||||
// provider
|
||||
procutil.fork(__filename, [
|
||||
'provider'
|
||||
, '--name', options.provider
|
||||
, '--connect-sub', options.bindDevPub
|
||||
, '--connect-push', options.bindDevPull
|
||||
].concat(cliutil.allUnknownArgs(arguments)))
|
||||
.catch(function(err) {
|
||||
log.error('provider died', err.stack)
|
||||
})
|
||||
// provider
|
||||
, procutil.fork(__filename, [
|
||||
'provider'
|
||||
, '--name', options.provider
|
||||
, '--connect-sub', options.bindDevPub
|
||||
, '--connect-push', options.bindDevPull
|
||||
].concat(cliutil.allUnknownArgs(arguments)))
|
||||
|
||||
// auth-mock
|
||||
procutil.fork(__filename, [
|
||||
'auth-mock'
|
||||
, '--port', options.authPort
|
||||
, '--secret', options.authSecret
|
||||
, '--app-url', util.format('http://localhost:%d/', options.appPort)
|
||||
])
|
||||
.catch(function(err) {
|
||||
log.error('auth-mock died', err.stack)
|
||||
})
|
||||
// auth-mock
|
||||
, procutil.fork(__filename, [
|
||||
'auth-mock'
|
||||
, '--port', options.authPort
|
||||
, '--secret', options.authSecret
|
||||
, '--app-url', util.format('http://localhost:%d/', options.appPort)
|
||||
])
|
||||
|
||||
// app
|
||||
procutil.fork(__filename, [
|
||||
'app'
|
||||
, '--port', options.appPort
|
||||
, '--secret', options.authSecret
|
||||
, '--auth-url', util.format('http://localhost:%d/', options.authPort)
|
||||
, '--connect-sub', options.bindAppPub
|
||||
, '--connect-push', options.bindAppPull
|
||||
].concat(function() {
|
||||
var extra = []
|
||||
if (options.disableWatch) {
|
||||
extra.push('--disable-watch')
|
||||
}
|
||||
return extra
|
||||
}()))
|
||||
// app
|
||||
, procutil.fork(__filename, [
|
||||
'app'
|
||||
, '--port', options.appPort
|
||||
, '--secret', options.authSecret
|
||||
, '--auth-url', util.format('http://localhost:%d/', options.authPort)
|
||||
, '--connect-sub', options.bindAppPub
|
||||
, '--connect-push', options.bindAppPull
|
||||
].concat(function() {
|
||||
var extra = []
|
||||
if (options.disableWatch) {
|
||||
extra.push('--disable-watch')
|
||||
}
|
||||
return extra
|
||||
}()))
|
||||
]
|
||||
|
||||
function shutdown() {
|
||||
log.info('Shutting down all child processes')
|
||||
procs.forEach(function(proc) {
|
||||
proc.cancel()
|
||||
})
|
||||
return Promise.settle(procs)
|
||||
}
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
log.info('Received SIGINT, waiting for processes to terminate')
|
||||
})
|
||||
|
||||
process.on('SIGTERM', function() {
|
||||
log.info('Received SIGTERM, waiting for processes to terminate')
|
||||
})
|
||||
|
||||
Promise.all(procs)
|
||||
.then(function() {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('app died', err.stack)
|
||||
log.fatal('Child process had an error', err.stack)
|
||||
return shutdown()
|
||||
.then(function() {
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue