-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyslogd.mjs
More file actions
executable file
·38 lines (33 loc) · 1.09 KB
/
Copy pathsyslogd.mjs
File metadata and controls
executable file
·38 lines (33 loc) · 1.09 KB
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
#!/usr/bin/env node
import 'dotenv/config';
import { createPool } from './src/db.mjs';
import { loadConfig } from './src/config.mjs';
import { createCollector } from './src/collector.mjs';
function createLogger() {
return {
info: (...args) => console.log('[info]', ...args),
error: (...args) => console.error('[error]', ...args),
};
}
const log = createLogger();
const config = loadConfig();
const pool = createPool(config.mysql);
const collector = createCollector({ pool, port: config.port, log });
async function shutdown(signal) {
log.info(`Shutting down on ${signal}`);
try {
await collector.shutdown();
} finally {
await pool.end();
}
process.exit(0);
}
process.on('SIGINT', () => void shutdown('SIGINT'));
process.on('SIGTERM', () => void shutdown('SIGTERM'));
process.on('uncaughtException', (error) => {
log.error('Uncaught exception', error?.stack || error?.message || error);
});
process.on('unhandledRejection', (error) => {
log.error('Unhandled rejection', error?.stack || error?.message || error);
});
await collector.start();