Implement pid file & checks

This commit is contained in:
Mononaut
2023-08-28 19:20:58 +09:00
parent 63a4810b11
commit 7dad00523f
7 changed files with 52 additions and 2 deletions

View File

@@ -91,11 +91,18 @@ class Server {
async startServer(worker = false): Promise<void> {
logger.notice(`Starting Mempool Server${worker ? ' (worker)' : ''}... (${backendInfo.getShortCommitHash()})`);
// Register cleanup listeners for exit events
['exit', 'SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'unhandledRejection'].forEach(event => {
process.on(event, () => { this.onExit(event); });
});
if (config.MEMPOOL.BACKEND === 'esplora') {
bitcoinApi.startHealthChecks();
}
if (config.DATABASE.ENABLED) {
DB.getPidLock();
await DB.checkDbConnection();
try {
if (process.env.npm_config_reindex_blocks === 'true') { // Re-index requests
@@ -306,6 +313,13 @@ class Server {
this.lastHeapLogTime = now;
}
}
onExit(exitEvent): void {
DB.releasePidLock();
process.exit(0);
}
}
((): Server => new Server())();