diff --git a/lib/roles/device/plugins/http.js b/lib/roles/device/plugins/http.js index 19517218..6e8b7741 100644 --- a/lib/roles/device/plugins/http.js +++ b/lib/roles/device/plugins/http.js @@ -76,7 +76,9 @@ module.exports = syrup.serial() var resolver = Promise.defer() function resolve() { - lifecycle.share('Proxy server', proxyServer) + lifecycle.share('Proxy server', proxyServer, { + end: false + }) resolver.resolve() } diff --git a/lib/util/lifecycle.js b/lib/util/lifecycle.js index 6f747182..fc41f506 100644 --- a/lib/util/lifecycle.js +++ b/lib/util/lifecycle.js @@ -2,6 +2,7 @@ var Promise = require('bluebird') var logger = require('./logger') var log = logger.createLogger('util:lifecycle') +var _ = require('lodash') function Lifecycle() { this.observers = [] @@ -9,16 +10,25 @@ function Lifecycle() { process.on('SIGTERM', this.graceful.bind(this)) } -Lifecycle.prototype.share = function(name, emitter) { - emitter.on('end', function() { - log.fatal('%s ended; we shall share its fate', name) - this.fatal() - }.bind(this)) +Lifecycle.prototype.share = function(name, emitter, options) { + _.defaults(options, { + end: true + , error: true + }) - emitter.on('error', function(err) { - log.fatal('%s had an error', name, err.stack) - this.fatal() - }.bind(this)) + if (options.end) { + emitter.on('end', function() { + log.fatal('%s ended; we shall share its fate', name) + this.fatal() + }.bind(this)) + } + + if (options.error) { + emitter.on('error', function(err) { + log.fatal('%s had an error', name, err.stack) + this.fatal() + }.bind(this)) + } return emitter }