forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (35 loc) · 1.01 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
/* eslint-disable global-require,import/no-dynamic-require */
/**
* Entry point for the application.
**/
const cp = require('child_process');
const pm2 = require('pm2');
const async = require('async');
const apps = require('./manifest.json').apps;
const args = process.argv.slice(2);
const group = args[0] || process.env.GROUP;
if (process.env.PROVIDER === 'gce') {
cp.execSync('curl -H "Metadata-Flavor: Google" -L http://metadata.google.internal/computeMetadata/v1/project/attributes/env > /usr/src/.env');
}
if (process.env.ROLE) {
// if role variable is set just run that script
require(`./svc/${process.env.ROLE}.js`);
} else if (group) {
pm2.connect(() => {
async.each(apps, (app, cb) => {
if (group === app.group) {
console.log(app.script, app.instances);
pm2.start(app.script, {
instances: app.instances,
}, cb);
}
}, (err) => {
if (err) {
console.error(err);
}
pm2.disconnect();
});
});
} else {
process.stdin.resume();
}