!7 sS iconID = #1101427; static double interval = 60.0, timeout = 30.0; // change for fast computers static int consecutiveFailsThreshold = 3; // TODO: change if loading sS osBotName = "Discord Bots OS"; sS vmArgs = "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/jdk.internal.module=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED --add-opens java.base/java.lang.module=ALL-UNNAMED --illegal-access=permit -Xmx1g"; sbool v6; static int consecutiveFails; static volatile S status; static TrayIcon trayIcon; sS osProgramID; p { // TODO osProgramID = or(get(args, 0), #1025342); // TODO: put "Restart OS Now" in consoleMemoryView()'s popup menu S myName = "Watch dog for " + osBotName; bot(myName); trayIcon = installTrayIcon(iconID, myName, r showConsole, "Restart " + osBotName + " Now", r restartOSNow, "Show Watch Dog Window", r showConsole, "Hide Watch Dog Window", r hideConsole, "Exit Watch Dog", rThread cleanKill); consoleIcon(iconID); //printWithDateAndTimeInThisThread(); doEvery(interval, r { bool ok = false; pcall { long time = sysNow(); S s = sendOptWithTimeout(timeout, osBotName, "live check"); if "i'm alive" { hideConsole(); ok = true; consecutiveFails = 0; setStatus(osBotName + " OK"); } else showConsole(); consoleStatus(ok ? "OK" : "FAIL"); } if (!ok) { ++consecutiveFails; printAndProgramLog(status = osBotName + " #" + consecutiveFails + " of " + consecutiveFailsThreshold); /*S stackTraces = sendOptWithTimeout(timeout, osBotName, "stack traces"); if (nempty(stackTraces)) { stackTraces = unquote(stackTraces); print(stackTraces); saveTextFile(newFile(stefansOS_watchDogStackTracesDir(), "discord-audio-stack-trace-" + ymd_minus_hms() + ".txt"), stackTraces); }*/ pcall { osFailActivity(); } } }); hideConsole(); sleep(); } svoid osFailActivity { if (consecutiveFails >= consecutiveFailsThreshold) restartOSNow(); } svoid restartOSNow { printAndProgramLog("RESTARTING " + osBotName + "."); consecutiveFails = 0; hardKillProgram(osProgramID, level := 9); nohupJavax(osProgramID, vmArgs); } answer { if "status" ret status; } svoid setStatus(S status) { printAndProgramLog(main.status = status); setTrayIconToolTip(trayIcon, status); }