mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Merge pull request #358 from Hornwitser/shutdown-logic
Shutdown logic changes.
This commit is contained in:
2 files changed
+19
-8
No files matched your search
@@ -477,11 +477,16 @@ async function saveUsers(databaseDirectory, file) {
|
||||
await fs.outputFile(filePath, JSON.stringify(serialized, null, 4));
|
||||
}
|
||||
|
||||
let shuttingDown = false;
|
||||
/**
|
||||
* Innitiate shutdown of master server
|
||||
*/
|
||||
async function shutdown() {
|
||||
logger.info("Shutting down");
|
||||
if (shuttingDown) {
|
||||
return;
|
||||
}
|
||||
shuttingDown = true;
|
||||
|
||||
let exitStartTime = Date.now();
|
||||
try {
|
||||
logger.info("Saving configs");
|
||||
@@ -1957,6 +1962,7 @@ async function startServer(args) {
|
||||
let secondSigint = false;
|
||||
process.on("SIGINT", () => {
|
||||
if (secondSigint) {
|
||||
setBlocking(true);
|
||||
logger.fatal("Caught second interrupt, terminating immediately");
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
@@ -1969,6 +1975,7 @@ async function startServer(args) {
|
||||
let secondSigterm = false;
|
||||
process.on("SIGTERM", () => {
|
||||
if (secondSigterm) {
|
||||
setBlocking(true);
|
||||
logger.fatal("Caught second termination, terminating immediately");
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
@@ -1978,13 +1985,9 @@ async function startServer(args) {
|
||||
logger.info("Caught termination signal, shutting down");
|
||||
shutdown();
|
||||
});
|
||||
|
||||
// terminal closed
|
||||
process.on("SIGHUP", () => {
|
||||
// No graceful cleanup, no warning out (stdout is likely closed.)
|
||||
// Don't close the terminal with the clusterio master in it.
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
logger.info("Terminal closed, shutting down");
|
||||
shutdown();
|
||||
});
|
||||
|
||||
await fs.ensureDir(masterConfig.get("master.database_directory"));
|
||||
|
||||
@@ -1384,6 +1384,9 @@ class Slave extends libLink.Link {
|
||||
* Stops all instances and closes the connection
|
||||
*/
|
||||
async shutdown() {
|
||||
if (this._shuttingDown) {
|
||||
return;
|
||||
}
|
||||
this._shuttingDown = true;
|
||||
this.connector.setTimeout(30);
|
||||
|
||||
@@ -1404,6 +1407,7 @@ class Slave extends libLink.Link {
|
||||
// Clear silly interval in pidfile library.
|
||||
pidusage.clear();
|
||||
} catch (err) {
|
||||
setBlocking(true);
|
||||
logger.error(`
|
||||
+--------------------------------------------------------------------+
|
||||
| Unexpected error occured while shutting down slave, please report |
|
||||
@@ -1629,7 +1633,7 @@ async function startSlave() {
|
||||
process.on("SIGTERM", () => {
|
||||
if (secondSigterm) {
|
||||
setBlocking(true);
|
||||
logger.fatal("Caught second termination signal, terminating immediately");
|
||||
logger.fatal("Caught second termination, terminating immediately");
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1638,6 +1642,10 @@ async function startSlave() {
|
||||
logger.info("Caught termination signal, shutting down");
|
||||
slave.shutdown();
|
||||
});
|
||||
process.on("SIGHUP", () => {
|
||||
logger.info("Terminal closed, shutting down");
|
||||
slave.shutdown();
|
||||
});
|
||||
|
||||
slaveConnector.once("connect", () => {
|
||||
logger.add(new libLoggingUtils.LinkTransport({ link: slave }));
|
||||
|
||||
Reference in new issue
Block a user