-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (41 loc) · 1.1 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
const config = require('config')
const redis = require("redis").createClient(config.dbConfig)
const Node = require(__dirname + '/lib/node')
const Web = require(__dirname + '/lib/web')
// initialize redis connection
redis.on("connect", function() {
console.log("Redis connected.")
})
redis.on("error", function(err) {
console.log("Redis Error ", err)
})
let options = Object.assign({redis: redis}, config)
// bootstrap node
let node = new Node(options)
if (process.env.POLL === 'true') {
node.init()
}
// bootstrap web server
let web = new Web(options)
if (process.env.WEB == 'true') {
web.init()
}
// Graceful shotdown application
let gracefulShutdown = function() {
console.log('Received kill signal, shutting down gracefully.')
node.stop()
redis.quit()
setTimeout(function(){
process.exit(0)
}, 1500)
}
// listen for TERM signal .e.g. kill
process.on('SIGTERM', gracefulShutdown)
// listen for INT signal e.g. Ctrl-C
process.on('SIGINT', gracefulShutdown)
// listen for shutdown signal from pm2
process.on('message', function(msg) {
if (msg == 'shutdown') {
gracefulShutdown()
}
})