forked from slothpixel/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (42 loc) · 1.17 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
/* eslint-disable global-require,import/no-dynamic-require */
/**
* Entry point for the application.
* */
const pm2 = require('pm2');
const async = require('async');
const { apps } = require('./manifest.json');
const arguments_ = process.argv.slice(2);
const group = arguments_[0] || process.env.GROUP;
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, callback) => {
if (group === app.group) {
console.log(app.script, app.instances);
pm2.start(app.script, {
instances: app.instances,
max_memory_restart: '2GB',
restartDelay: 10000,
}, (error) => {
if (error) {
// Log the error and continue
console.error(error);
}
callback();
});
}
}, (error) => {
if (error) {
console.error(error);
}
pm2.disconnect();
});
});
// Clean up the logs once an hour
setInterval(() => pm2.flush(), 3600 * 1000);
} else {
// Block indefinitely (keep process alive for Docker)
process.stdin.resume();
}