Handle SIGHUP gracefully

Invoke shutdown instead of exiting immediately when SIGHUP is received,
and do the same on both slave and master for signals received.
This commit is contained in:
Hornwitser committed 2021-02-17 17:49:54 +01:00
1 parent 4ca092f351
commit 9660fa0801
2 files changed
+7 -7

No files matched your search

+2 -6
View File
@@ -1985,13 +1985,9 @@ async function startServer(args) {
logger.info("Caught termination signal, shutting down"); logger.info("Caught termination signal, shutting down");
shutdown(); shutdown();
}); });
// terminal closed
process.on("SIGHUP", () => { process.on("SIGHUP", () => {
// No graceful cleanup, no warning out (stdout is likely closed.) logger.info("Terminal closed, shutting down");
// Don't close the terminal with the clusterio master in it. shutdown();
// eslint-disable-next-line no-process-exit
process.exit(1);
}); });
await fs.ensureDir(masterConfig.get("master.database_directory")); await fs.ensureDir(masterConfig.get("master.database_directory"));
+5 -1
View File
@@ -1633,7 +1633,7 @@ async function startSlave() {
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
if (secondSigterm) { if (secondSigterm) {
setBlocking(true); setBlocking(true);
logger.fatal("Caught second termination signal, terminating immediately"); logger.fatal("Caught second termination, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line no-process-exit
process.exit(1); process.exit(1);
} }
@@ -1642,6 +1642,10 @@ async function startSlave() {
logger.info("Caught termination signal, shutting down"); logger.info("Caught termination signal, shutting down");
slave.shutdown(); slave.shutdown();
}); });
process.on("SIGHUP", () => {
logger.info("Terminal closed, shutting down");
slave.shutdown();
});
slaveConnector.once("connect", () => { slaveConnector.once("connect", () => {
logger.add(new libLoggingUtils.LinkTransport({ link: slave })); logger.add(new libLoggingUtils.LinkTransport({ link: slave }));