diff host/admin/src/private/lib/monitor.luan @ 2021:b8e5d53c4fc9

admin monitors scheduler
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 20 Oct 2025 14:45:27 -0600
parents 301a6561fb6b
children 969291201e12
line wrap: on
line diff
--- a/host/admin/src/private/lib/monitor.luan	Sun Oct 05 20:43:42 2025 -0600
+++ b/host/admin/src/private/lib/monitor.luan	Mon Oct 20 14:45:27 2025 -0600
@@ -14,15 +14,16 @@
 
 
 local who_monitors_who = {
-	-- ["admin.me.luan.software"] = "admin.me.luan.software"
 	["admin.s1.luan.software"] = "admin.s2.luan.software"
 	["admin.s2.luan.software"] = "admin.s1.luan.software"
 }
 local frequency = Time.period{minutes=2}
+local url
 
 --[[  -- for development
---who_monitors_who["admin.me.luan.software"] = "admin.me.luan.software"
-frequency = Time.period{seconds=20}
+who_monitors_who["admin.me.luan.software"] = "admin.me.luan.software"
+url = "http://admin.me.luan.software:8080/hi.txt"
+frequency = Time.period{seconds=30}
 Config.email_to = "fschmidt@gmail.com"
 --]]
 
@@ -35,42 +36,53 @@
 	return true
 end
 
-local url = "https://"..domain.."/hi"
+url = url or "https://"..domain.."/hi.txt"
 local options = { time_out = Time.period{seconds=20} }
 
 local function init_check()
 	local fails = 0
+	local last_page
+
+	local function fail()
+		fails = fails + 1
+		if fails < 2 then return end
+		try
+			local s = Utils.ssh(domain,"/Users/administrator/luan/host/restart.sh monitoring")
+			if trim(s) == "stopped with stop script" then
+				logger.info("stopped with stop script")
+			else
+				logger.error("restart successful\n"..s)
+				Utils.send_mail {
+					Subject = domain.." restarted"
+					body = s
+				}
+			end
+			fails = 0
+		catch e
+			logger.error("restart failed: "..e.get_message())
+			if fails < 5 then
+				Utils.send_mail {
+					Subject = domain.." restart failed"
+					body = e.get_message()
+				}
+			end
+		end
+	end
 
 	return function()
 		try
 			local page = uri(url,options).read_text()
+			if page == last_page then
+				logger.error("Scheduler not working on "..domain)
+				fail()
+				return
+			end
+			last_page = page
 			fails = 0
 			logger.info(domain.." is okay")
 		catch e
 			logger.error("Error connecting to "..domain..": "..e.get_message())
-			fails = fails + 1
-			if fails < 2 then return end
-			try
-				local s = Utils.ssh(domain,"/Users/administrator/luan/host/restart.sh monitoring")
-				if trim(s) == "stopped with stop script" then
-					logger.info("stopped with stop script")
-				else
-					logger.error("restart successful\n"..s)
-					Utils.send_mail {
-						Subject = domain.." restarted"
-						body = s
-					}
-				end
-				fails = 0
-			catch e
-				logger.error("restart failed: "..e.get_message())
-				if fails < 5 then
-					Utils.send_mail {
-						Subject = domain.." restart failed"
-						body = e.get_message()
-					}
-				end
-			end
+			fail()
 		end
 	end
 end