Download Jar. Uses 5404K of libraries. Click here for Pure Java version (11411L/82K).
1 | !7 |
2 | |
3 | sS iconID = /*#1101425*/#1101427; |
4 | static double delay = 10.0, timeout = 10.0; // change for fast computers |
5 | static int consecutiveFailsThreshold = 3; // TODO: change if loading |
6 | sS osBotName = "Stefan's OS."; |
7 | |
8 | sbool v6; |
9 | static int consecutiveFails; |
10 | static volatile S status; |
11 | static TrayIcon trayIcon; |
12 | |
13 | svoid activateOS { |
14 | sendOpt("Stefan'S OS", "activate frames"); |
15 | } |
16 | |
17 | sS osProgramID; |
18 | |
19 | p { |
20 | // TODO |
21 | osProgramID = or(get(args, 0), #1016005); |
22 | S homeDir = get(args, 0); |
23 | |
24 | if (isAbsolutePath(homeDir)) _userHome = args[0]; |
25 | print("Home: " + _userHome); |
26 | |
27 | // TODO: put "Restart OS Now" in consoleMemoryView()'s popup menu |
28 | |
29 | bot(stefansOS_watchDogBotName()); |
30 | trayIcon = installTrayIcon(iconID, dropSuffix(".", stefansOS_watchDogBotName()), |
31 | r showConsole, |
32 | "Restart OS Now", r restartOSNow, |
33 | "Show Watch Dog Window", r showConsole, |
34 | "Hide Watch Dog Window", r hideConsole, |
35 | "Exit Watch Dog", rThread cleanKill); |
36 | consoleIcon(iconID); |
37 | //printWithDateAndTimeInThisThread(); |
38 | doEvery(delay, r { |
39 | bool ok = false; |
40 | pcall { |
41 | long time = sysNow(); |
42 | S s = sendOptWithTimeout(timeout, osBotName, "swing latency"); |
43 | if (isInteger(s)) { |
44 | hideConsole(); |
45 | ok = true; |
46 | consecutiveFails = 0; |
47 | setStatus("Stefan's OS OK - Swing latency " + s + " ms, " + (sysNow()-time) + " ms"); |
48 | //v6 = isProgramRunning(#1016478); |
49 | S progID = evalWithTimeoutOrNull(timeout, func -> S { |
50 | send("Stefan's OS", "program id") |
51 | }); |
52 | if (isSnippetID(progID)) osProgramID = or(progID, osProgramID); |
53 | } else |
54 | showConsole(); |
55 | consoleStatus(ok ? "OK" : "FAIL"); |
56 | } |
57 | |
58 | if (!ok) { |
59 | ++consecutiveFails; |
60 | printAndProgramLog(status = "Stefan's OS fail #" + consecutiveFails + " of " + consecutiveFailsThreshold); |
61 | S stackTraces = sendOptWithTimeout(timeout, osBotName, "stack traces"); |
62 | if (nempty(stackTraces)) { |
63 | stackTraces = unquote(stackTraces); |
64 | print(stackTraces); |
65 | saveTextFile(newFile(stefansOS_watchDogStackTracesDir(), "stack-trace-" + ymd_minus_hms() + ".txt"), stackTraces); |
66 | } |
67 | pcall { osFailActivity(); } |
68 | } |
69 | }); |
70 | hideConsole(); |
71 | |
72 | quickRestartOnSocketLoss(); |
73 | sleep(); |
74 | } |
75 | |
76 | svoid osFailActivity { |
77 | if (consecutiveFails >= consecutiveFailsThreshold) |
78 | restartOSNow(); |
79 | } |
80 | |
81 | svoid restartOSNow { |
82 | printAndProgramLog("RESTARTING STEFAN'S OS " + (v6 ? "v6" : "v5") + "."); |
83 | consecutiveFails = 0; |
84 | hardKillStefansOS(); |
85 | nohupJavax(osProgramID); |
86 | } |
87 | |
88 | answer { |
89 | if "status" ret status; |
90 | } |
91 | |
92 | // TODO |
93 | svoid quickRestartOnSocketLoss { |
94 | /*int port = getVMPortForBot(osBotName); |
95 | if (port != 0) talkTo(port);*/ |
96 | } |
97 | |
98 | svoid setStatus(S status) { |
99 | printAndProgramLog(main.status = status); |
100 | setTrayIconToolTip(trayIcon, status); |
101 | } |
Began life as a copy of #1012699
download show line numbers debug dex old transpilations
Travelled to 26 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dbzfplsxganw, ekrmjmnbrukm, elmgxqgtpvxh, fzcpzdstiiyc, gwrvuhgaqvyk, hpgrupgrauku, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, jozkyjcghlvl, lqnftawlhpir, mqqgnosmbjvj, omdjrrnzbjjv, pcsjzfqafodr, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wpzdwgqboxjy, xrpafgyirdlv, znvaruejrphg
No comments. add comment
Snippet ID: | #1019683 |
Snippet name: | Watch Dog for Stefan's OS [external part, see #1019696] |
Eternal ID of this version: | #1019683/38 |
Text MD5: | ea58e9d6de587da921c012bddea60f05 |
Transpilation MD5: | 03600803d0e3f4b3a09cb1862f55bcc5 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-14 17:26:41 |
Source code size: | 2888 bytes / 101 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 540 / 10750 |
Version history: | 37 change(s) |
Referenced in: | [show references] |