forked from governify/reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.19 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
'use strict';
if (process.env.NEW_RELIC_APP_NAME && process.env.NEW_RELIC_LICENSE_KEY) require('newrelic');
const governify = require('governify-commons');
const logger = governify.getLogger().tag('index');
logger.info('Deploy request received');
let server = null;
governify.init({
configurations: [{
name: 'main',
location: './configurations/main.' + (process.env.NODE_ENV || 'development') + '.yaml',
default: true
}]
}).then(function (commonsMiddleware) {
server = require('./server');
server.deploy(null, commonsMiddleware, function () {
logger.info('Deploy successfully done');
});
});
// quit on ctrl-c when running docker in terminal
process.on('SIGINT', function onSigint() {
logger.info('Got SIGINT (aka ctrl-c in docker). Graceful shutdown ', new Date().toISOString());
shutdown();
});
// quit properly on docker stop
process.on('SIGTERM', function onSigterm() {
logger.info('Got SIGTERM (docker container stop). Graceful shutdown ', new Date().toISOString());
shutdown();
});
// shut down server
function shutdown() {
server.undeploy(function onServerClosed(err) {
if (err) {
logger.error(err);
process.exitCode = 1;
}
process.exit();
});
}