-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (48 loc) · 1.46 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* needs to be called first */
const DI = require('./src/DI')
let startUpCheck = DI.container.get(DI.FILETYPES.StartUpCheck)
const utils = require('./src/utils')
const Promise = require('bluebird')
const logger = require('./src/logger')
// https://www.exratione.com/2013/05/die-child-process-die/
process.once('uncaughtException', function (error) {
logger.error('UNCAUGHT EXCEPTION')
logger.error(error.stack)
})
const Conductor = require('./src/orchestration/conductor')
let aschService = DI.container.get(DI.FILETYPES.Service)
let appConfig = DI.container.get(DI.DEPENDENCIES.Config)
aschService.notifier.on('exit', function (code) {
logger.warn(`asch-node terminated with code ${code}`)
})
process.on('SIGTERM', function () {
logger.verbose('SIGTERM', { meta: 'inverse' })
aschService.stop()
process.exit(0)
})
process.on('SIGINT', function () {
// ctrl+c
logger.verbose('SIGTERM', { meta: 'inverse' })
aschService.stop()
process.exit(0)
})
logger.verbose('starting asch-redeploy...')
startUpCheck.check()
.then(() => {
return aschService.start()
})
.then(() => {
let ms = 7000
logger.verbose(`waiting for ${ms}ms`)
return Promise.delay(ms)
})
.then(() => {
logger.verbose('starting to orchestrate...')
let conductor = new Conductor(aschService, appConfig)
return conductor.orchestrate()
})
.catch((err) => { // last error handler
logger.error(err.message)
logger.verbose(err.stack)
utils.endProcess()
})