-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (49 loc) · 1.41 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* index is the starting point for these example setups.
* Since the examples uses alot of the same code, i made it dynamic with the help of dynamic import and env
*/
import dotenv from 'dotenv/config';
import { config } from './shared/globals.js';
import { runOSDiagnostics, stopOSDiagnostics } from "./shared/utils/osDiagnostics.js";
const { SERVICE } = config;
console.log(config)
if(!SERVICE)
{
throw new Error('SERVICE is not defined in the .env file');
}
let core;
// Loads in the service based on SERVICE in env
// env service is case-sensitive
try
{
core = await import(`./${ SERVICE }/main.js`);
core = core[SERVICE];
}
catch(error)
{
console.error(error)
}
runOSDiagnostics((data) =>
{
//TODO: report and create limits
core?.runDiagnostics(data);
}, 5000);
// Override SIGINT signal handling, SIGINT is the interupt signal from ctrl+c in terminal
process.on('SIGINT', handleExit);
process.on('SIGTERM', handleExit);
process.on('SIGUSR1', handleSIGUSR1);
async function handleSIGUSR1()
{
await core?.handleSIGUSR1();
// might be a good use to signal an eventual shutdown. like, when all games are over, terminate,
// or to read a file containing instructions
}
async function handleExit()
{
console.log("Terminating");
stopOSDiagnostics();
process.removeListener('SIGUSR1', handleSIGUSR1);
await core?.handleExit();
// remove us from S3
process.exit();
}