Skip to content

Commit

Permalink
switch index to esm and add ecosystem.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 5, 2023
1 parent 470d322 commit 1332efd
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 280 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
- Get a terminal into the running container: `docker exec -it odota-core bash`
- The process manager `pm2` is used to manage the individual services. Each is run as a separate Node.js process.
- `pm2 list` See the currently running services.
- `pm2 start manifest.json` Start all the services according to the manifest file
- `pm2 start manifest.json --only web` Starts a specific service
- `pm2 start ecosystem.config.js` Start all the services
- `pm2 start ecosystem.config.js --only web` Starts a specific service
- `pm2 stop web` Stop a specific service
- `pm2 stop all` Stop all the services
- `pm2 logs web` Inspect the output of a service
Expand Down
2 changes: 1 addition & 1 deletion docker/main-launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Rebuild to replace mapped directory build
npm run build

pm2 start manifest.json --only web
pm2 start ecosystem.config.js --only web

# We shall now display logs indefinitely
pm2 logs
157 changes: 157 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
const { GROUP, NODE_ENV } = require('./config.js');

let arr = [
{
"name": "web",
"script": "svc/web.mjs",
"group": "web",
},
{
"name": "retriever",
"script": "svc/retriever.mjs",
"group": "retriever",
},
{
"name": "proxy",
"script": "svc/proxy.mjs",
"group": "proxy",
},
{
"name": "parser",
"script": "svc/parser.mjs",
},
{
"name": "apiadmin",
"script": "svc/apiadmin.mjs",
"group": "backend",
},
{
"name": "mmr",
"script": "svc/mmr.mjs",
"group": "backend",
},
{
"name": "profiler",
"script": "svc/profiler.mjs",
"group": "backend",
},
{
"name": "scanner",
"script": "svc/scanner.mjs",
"group": "backend",
},
{
"name": "fullhistory",
"script": "svc/fullhistory.mjs",
"group": "backend",
},
{
"name": "fullhistory",
"script": "svc/autofullhistory.mjs",
"group": "backend",
},
{
"name": "monitor",
"script": "svc/monitor.mjs",
"group": "backend",
},
{
"name": "gcdata",
"script": "svc/gcdata.mjs",
"group": "backend",
},
{
"name": "buildsets",
"script": "svc/buildsets.mjs",
"group": "backend",
},
{
"name": "cosmetics",
"script": "svc/cosmetics.mjs",
"group": "backend",
},
{
"name": "distributions",
"script": "svc/distributions.mjs",
"group": "backend",
},
{
"name": "heroes",
"script": "svc/heroes.mjs",
"group": "backend",
},
{
"name": "herostats",
"script": "svc/herostats.mjs",
"group": "backend",
},
{
"name": "items",
"script": "svc/items.mjs",
"group": "backend",
},
{
"name": "leagues",
"script": "svc/leagues.mjs",
"group": "backend",
},
{
"name": "livegames",
"script": "svc/livegames.mjs",
"group": "backend",
},
{
"name": "proplayers",
"script": "svc/proplayers.mjs",
"group": "backend",
},
{
"name": "teams",
"script": "svc/teams.mjs",
"group": "backend",
},
{
"name": "scenarios",
"script": "svc/scenarios.mjs",
"group": "backend",
},
{
"name": "scenariosCleanup",
"script": "svc/scenariosCleanup.mjs",
"group": "backend",
},
{
"name": "counts",
"script": "svc/counts.mjs",
"group": "backend",
},
{
"name": "syncSubs",
"script": "svc/syncSubs.mjs",
"group": "backend",
},
{
"name": "cassandraDelete",
"script": "svc/cassandraDelete.mjs",
"group": "backend",
}
];

// If GROUP is set filter to only the matching group
arr = arr.filter(app => !GROUP || app.group === GROUP);

const apps = arr.map(app => {
const dev = NODE_ENV === 'development';
return {
...app,
watch: dev ? true : false,
ignore_watch: [".git", "node_modules"],
exec_mode: 'fork',
instances: 1,
}
});

module.exports = {
apps
};

45 changes: 0 additions & 45 deletions index.js

This file was deleted.

27 changes: 27 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Entry point for the application.
* */
import cp from 'child_process';
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'
);
}
// Do this after the metadata download since it uses config
const ecosystem = await import('./ecosystem.config.js');
if (process.env.ROLE) {
// if role variable is set just run that script
const app = ecosystem.apps.find((app) => app.name === process.env.ROLE);
import('./' + app.script);
} else if (process.env.GROUP) {
// or run the group with pm2
cp.execSync(
'pm2 start ecosystem.config.js'
);
setInterval(() => {
cp.execSync('pm2 flush all');
}, 60 * 60 * 1000);
} else {
// Block indefinitely (keep process alive for Docker)
process.stdin.resume();
}
Loading

0 comments on commit 1332efd

Please sign in to comment.