forked from faangbait/phoenix-os-bitburner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbin.keepalive.js
41 lines (33 loc) · 1.14 KB
/
sbin.keepalive.js
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
39
40
41
/**
* @typedef {import(".").NS} ns
*
*/
export async function main(ns) {
var count = 0;
while (true) {
if (count > 120) {
ns.tprint("scheduled reboot");
ns.ps("home").filter(process => process.filename != "sbin.keepalive.js").forEach(process => ns.kill(process.pid));
ns.run("phoenix.js");
count = 0;
}
if (ns.ps("home").filter(process => process.filename == "phoenix.js").length != 1) {
ns.run("phoenix.js");
ns.print("phoenix not found");
}
try {
let heartbeat = ns.peek(20);
let curtime = new Date().valueOf();
ns.print((curtime - heartbeat)/1000, " seconds since last heartbeat");
if ((curtime - heartbeat)/1000 > 300) {
throw "Heartbeat is old.";
}
} catch (e) {
ns.tprint("error ", e);
ns.ps("home").filter(process => process.filename != "sbin.keepalive.js").forEach(process => ns.kill(process.pid));
ns.run("phoenix.js");
}
await ns.sleep(60000);
count++;
}
}