Merge pull request #358 from Hornwitser/shutdown-logic

Shutdown logic changes.
This commit is contained in:
Hornwitser authored and GitHub committed 2021-02-17 21:18:11 +01:00
commit 207a28cb44
2 files changed
+19 -8

No files matched your search

+10 -7
View File
@@ -477,11 +477,16 @@ async function saveUsers(databaseDirectory, file) {
await fs.outputFile(filePath, JSON.stringify(serialized, null, 4)); await fs.outputFile(filePath, JSON.stringify(serialized, null, 4));
} }
let shuttingDown = false;
/** /**
* Innitiate shutdown of master server * Innitiate shutdown of master server
*/ */
async function shutdown() { async function shutdown() {
logger.info("Shutting down"); if (shuttingDown) {
return;
}
shuttingDown = true;
let exitStartTime = Date.now(); let exitStartTime = Date.now();
try { try {
logger.info("Saving configs"); logger.info("Saving configs");
@@ -1957,6 +1962,7 @@ async function startServer(args) {
let secondSigint = false; let secondSigint = false;
process.on("SIGINT", () => { process.on("SIGINT", () => {
if (secondSigint) { if (secondSigint) {
setBlocking(true);
logger.fatal("Caught second interrupt, terminating immediately"); logger.fatal("Caught second interrupt, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line no-process-exit
process.exit(1); process.exit(1);
@@ -1969,6 +1975,7 @@ async function startServer(args) {
let secondSigterm = false; let secondSigterm = false;
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
if (secondSigterm) { if (secondSigterm) {
setBlocking(true);
logger.fatal("Caught second termination, 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);
@@ -1978,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"));
+9 -1
View File
@@ -1384,6 +1384,9 @@ class Slave extends libLink.Link {
* Stops all instances and closes the connection * Stops all instances and closes the connection
*/ */
async shutdown() { async shutdown() {
if (this._shuttingDown) {
return;
}
this._shuttingDown = true; this._shuttingDown = true;
this.connector.setTimeout(30); this.connector.setTimeout(30);
@@ -1404,6 +1407,7 @@ class Slave extends libLink.Link {
// Clear silly interval in pidfile library. // Clear silly interval in pidfile library.
pidusage.clear(); pidusage.clear();
} catch (err) { } catch (err) {
setBlocking(true);
logger.error(` logger.error(`
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
| Unexpected error occured while shutting down slave, please report | | Unexpected error occured while shutting down slave, please report |
@@ -1629,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);
} }
@@ -1638,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 }));