Separate device functionality into plugins.

This commit is contained in:
Simo Kinnunen
2014-03-14 20:18:53 +09:00
parent d61a70fda5
commit 3d20b06f7f
24 changed files with 1277 additions and 700 deletions

View File

@@ -0,0 +1,38 @@
var Promise = require('bluebird')
var syrup = require('syrup')
var logger = require('../../../util/logger')
module.exports = syrup()
.define(function(options) {
var log = logger.createLogger('device:plugins: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)
}
}
})