!7 sbool smartBotToo = true; sS url = "http://localhost:8080/1010504/raw/number-of-threads"; sS smartBotURL = "http://localhost:4678/number-of-threads"; static double timeout = 60.0, delay = 30.0; static int consecutiveFailsThreshold = 2; static int consecutiveFailsThresholdWhenLoading = 20; static int consecutiveFails; static volatile S status; p { bot("New Eleu Watch Dog."); if (smartBotToo) thread "Smart Bot Loop" { smartBotLoop(); } printWithDateAndTimeInThisThread(); repeat with sleep delay { bool ok = false, loading = false; pcall { long time = sysNow(); S s = loadPageWithTimeout(url, timeout); if (startsWith(s, "LOADING")) loading = true; if (isInteger(s)) { ok = true; consecutiveFails = 0; print(status = "Server OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms"); } } if (!ok) { ++consecutiveFails; print(status = "Server fail #" + consecutiveFails + " of " + actualThreshold(loading) + (loading ? " (loading)" : "")); pcall { serverFailActivity(loading); } } } } static int actualThreshold(bool loading) { ret loading ? consecutiveFailsThresholdWhenLoading : consecutiveFailsThreshold; } svoid serverFailActivity(bool loading) { if (consecutiveFails == actualThreshold(loading)) { print("RESTARTING ELEU."); consecutiveFails = 0; hardKillProgram(#1013896); nohupJavax(#1013896); } } answer { if "status" ret status; } svoid smartBotLoop { int consecutiveFails = 0; S status = ""; printWithDateAndTimeInThisThread(); repeat with sleep delay { bool ok = false, loading = false; pcall { long time = sysNow(); S s = loadPageWithTimeout(smartBotURL, timeout); if (startsWith(s, "LOADING")) loading = true; if (isInteger(s)) { ok = true; consecutiveFails = 0; print(status = "Smart Bot OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms"); } } if (!ok) { ++consecutiveFails; print(status = "Smart Bot fail #" + consecutiveFails + " of " + actualThreshold(loading) + (loading ? " (loading)" : "")); pcall { if (smartBotFailActivity(consecutiveFails, loading)) consecutiveFails = 0; } } } } sbool smartBotFailActivity(int consecutiveFails, bool loading) { if (consecutiveFails == actualThreshold(loading)) { print("RESTARTING SMART BOT."); hardKillProgram(#1010745); nohupJavaxHeadless(#1010745); true; } false; }