Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit b1d7d31

Browse files
committed
Feat: add exit command
1 parent a46e6fc commit b1d7d31

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/app.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,27 @@ logger.info($t("app.exitTip"));
122122
logger.info("----------------------------");
123123
console.log("");
124124

125+
async function processExit() {
126+
try {
127+
console.log("");
128+
logger.warn("Program received EXIT command.");
129+
await InstanceSubsystem.exit();
130+
logger.info("Exit.");
131+
} catch (err) {
132+
logger.error("ERROR:", err);
133+
} finally {
134+
process.exit(0);
135+
}
136+
}
137+
125138
["SIGTERM", "SIGINT", "SIGQUIT"].forEach(function (sig) {
126-
process.on(sig, async function () {
127-
try {
128-
console.log("\n\n\n\n");
129-
logger.warn(`${sig} close process signal detected.`);
130-
await InstanceSubsystem.exit();
131-
logger.info("Exit...");
132-
} catch (err) {
133-
logger.error("ERROR:", err);
134-
} finally {
135-
process.exit(0);
136-
}
139+
process.on(sig, () => {
140+
logger.warn(`${sig} close process signal detected.`);
141+
processExit();
137142
});
138143
});
144+
145+
process.stdin.on("data", (v) => {
146+
const command = v.toString().replace("\n", "").replace("\r", "").trim().toLowerCase();
147+
if (command === "exit") processExit();
148+
});

0 commit comments

Comments
 (0)