-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestarter.js
More file actions
35 lines (31 loc) · 1.26 KB
/
restarter.js
File metadata and controls
35 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const intercom = require("./pmng_server/intercom/intercom_client").connect();
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
(async () => {
while(true) {
let input = (await new Promise((resolve) => {
readline.question("Enter the name of the process to restart or .exit to exit: ", resolve);
})).trim();
if(input != "") {
if(input == ".exit") {
process.exit();
} else {
try {
let resp = await intercom.sendPromise("subprocesses", {id: input, command: "restart"});
console.log(resp);
await new Promise((resolve) => {
setTimeout(resolve, 1000);
});
let checkResp = await intercom.sendPromise("subprocesses", {id: input, command: "check"});
if(checkResp.running) {
console.log("SUCCESS: Process restarted and running (checked via isRunning).");
} else throw "Process restarted but not found running.";
} catch(error) {
console.log("FAILED:", error);
}
}
}
}
})();