2015-04-03 03:28:37 +02:00
|
|
|
var sleep = require('sleep');
|
2015-04-04 01:17:38 +02:00
|
|
|
sleep.sleep(15);
|
2015-02-11 23:54:33 +01:00
|
|
|
|
2015-04-04 03:20:12 +02:00
|
|
|
var nodeModel = require('./lib/node');
|
|
|
|
|
2015-02-16 17:44:26 +01:00
|
|
|
var node = new nodeModel();
|
2015-02-12 13:26:47 +01:00
|
|
|
|
|
|
|
var gracefulShutdown = function() {
|
2015-03-27 12:38:41 +01:00
|
|
|
console.warn("Received kill signal, shutting down gracefully.");
|
2015-02-12 13:26:47 +01:00
|
|
|
|
|
|
|
node.stop();
|
2015-03-27 12:38:41 +01:00
|
|
|
console.info("Closed node watcher");
|
2015-02-12 13:26:47 +01:00
|
|
|
|
|
|
|
setTimeout(function(){
|
2015-03-27 12:38:41 +01:00
|
|
|
console.info("Closed out remaining connections.");
|
2015-02-18 05:39:33 +01:00
|
|
|
process.exit(0)
|
2015-02-12 13:26:47 +01:00
|
|
|
}, 2*1000);
|
2015-02-11 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2015-02-12 13:26:47 +01:00
|
|
|
// listen for TERM signal .e.g. kill
|
|
|
|
process.on('SIGTERM', gracefulShutdown);
|
|
|
|
|
|
|
|
// listen for INT signal e.g. Ctrl-C
|
|
|
|
process.on('SIGINT', gracefulShutdown);
|
2015-02-11 23:21:10 +01:00
|
|
|
|
2015-02-27 00:24:43 +01:00
|
|
|
// listen for shutdown signal from pm2
|
2015-02-18 05:39:33 +01:00
|
|
|
process.on('message', function(msg) {
|
|
|
|
if (msg == 'shutdown')
|
|
|
|
gracefulShutdown();
|
|
|
|
});
|
2015-02-11 23:21:10 +01:00
|
|
|
|
2015-02-12 23:30:12 +01:00
|
|
|
module.exports = node;
|