-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (27 loc) · 890 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var domain = require('domain').create()
module.exports = function(system, options) {
if (!system) throw new Error('system is required')
var logger = options && options.logger || console
var underlyingRunner
function start(cb) {
domain.on('error', function(err){
logger.error('Unhandled domain exception. Invoking shutdown.')
if (err) logger.error(err.stack)
underlyingRunner.stop(function() {
process.exit(1)
})
})
domain.run(function() {
underlyingRunner = (options && options.runner || require('systemic-service-runner'))(system, options)
underlyingRunner.start(cb)
})
}
function stop(cb) {
if (!underlyingRunner) return cb()
underlyingRunner.stop(cb)
}
return {
start: start,
stop: stop
}
}