Skip to content

Commit

Permalink
fix: end on SIGTERM or SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlustra committed Jun 29, 2021
1 parent 5eb2ffb commit 9207500
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,17 @@ async function startServer() {
await new Promise<void>((resolve) => httpServer.listen(port, resolve));

async function closeServer() {
logger.crit("Stopping Server");
tryQuietly(frontend.close);
tryQuietly(connectorSubscription.unsubscribe);
tryQuietly(agentSubscription.unsubscribe);
tryQuietly(loggingLevelSubscription.unsubscribe);
tryQuietly(api.stop);
tryQuietly(() => httpServer.close(() => logger.info("HTTP Server Closed")));
logger.crit("Server Stopped");
logger.info("Stopping Server");
await tryQuietly(frontend.close);
await tryQuietly(connectorSubscription.unsubscribe);
await tryQuietly(agentSubscription.unsubscribe);
await tryQuietly(loggingLevelSubscription.unsubscribe);
await tryQuietly(api.stop);
await tryQuietly(() =>
httpServer.close(() => logger.info("HTTP Server Closed"))
);
logger.info("Server Stopped");
process.exit(0);
}

process.on("SIGTERM", closeServer);
Expand Down

0 comments on commit 9207500

Please sign in to comment.