Replace device:support:quit with util:lifecycle, which is usable by non-device processes too.

This commit is contained in:
Simo Kinnunen
2014-04-01 21:41:58 +09:00
parent e17f306d30
commit d6604bcda8
11 changed files with 75 additions and 179 deletions

View File

@@ -1,38 +0,0 @@
var Promise = require('bluebird')
var syrup = require('syrup')
var logger = require('../../../util/logger')
module.exports = syrup.serial()
.define(function() {
var log = logger.createLogger('device:support:quit')
var cleanup = []
function graceful() {
log.info('Winding down for graceful exit')
var wait = Promise.all(cleanup.map(function(fn) {
return fn()
}))
return wait.then(function() {
process.exit(0)
})
}
function fatal() {
log.fatal('Shutting down due to fatal error')
process.exit(1)
}
process.on('SIGINT', graceful)
process.on('SIGTERM', graceful)
return {
graceful: graceful
, fatal: fatal
, observe: function(promise) {
cleanup.push(promise)
}
}
})