-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reboot.ts
38 lines (30 loc) · 837 Bytes
/
reboot.ts
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
36
37
38
import { catchExec, connect, end, exec } from '../../ssh.js';
import { ACCESS } from '../../types/acess.js';
export default async (VPS: ACCESS): Promise<true> => {
try {
await catchExec(
"sudo shutdown -r +0 \"`date '+%H:%M:%S' -d '+2 seconds'`\" & disown"
);
} catch (quiet) {}
try {
await end();
} catch (quiet) {}
return new Promise((resolve, reject) => {
let count = 0;
console.log('\n\x1b[0m\x1b[33m\x1b[1m⦿ Restarting\x1b[0m');
const reconnect = setInterval(async () => {
if (count >= 30) {
clearInterval(reconnect);
reject('Restarting Failed!');
}
try {
await connect(VPS);
clearInterval(reconnect);
await exec('history -c');
resolve(true);
} catch (quiet) {
count++;
}
}, 15000);
});
};