Feat: add exit command

This commit is contained in:
unitwk 2022-11-21 21:42:12 +08:00
parent 7b6a465127
commit 17ceea3b69

View File

@ -134,3 +134,27 @@ function startUp(port: number, host?: string) {
}
startUp(systemConfig.httpPort, systemConfig.httpIp);
async function processExit() {
try {
console.log("");
logger.warn("Program received EXIT command.");
logger.info("Exit.");
} catch (err) {
logger.error("ERROR:", err);
} finally {
process.exit(0);
}
}
["SIGTERM", "SIGINT", "SIGQUIT"].forEach(function (sig) {
process.on(sig, () => {
logger.warn(`${sig} close process signal detected.`);
processExit();
});
});
process.stdin.on("data", (v) => {
const command = v.toString().replace("\n", "").replace("\r", "").trim().toLowerCase();
if (command === "exit") processExit();
});