Mercurial Hosting > luan
changeset 2021:b8e5d53c4fc9 default tip
admin monitors scheduler
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 20 Oct 2025 14:45:27 -0600 |
parents | 163f88f7ee00 |
children | |
files | host/admin/src/hi.luan host/admin/src/hi.txt.luan host/admin/src/private/lib/monitor.luan |
diffstat | 3 files changed, 58 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/host/admin/src/hi.luan Sun Oct 05 20:43:42 2025 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -local Io = require "luan:Io.luan" -local Http = require "luan:http/Http.luan" - - -return function() - Io.stdout = Http.response.text_writer() - %>hi<% -end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/admin/src/hi.txt.luan Mon Oct 20 14:45:27 2025 -0600 @@ -0,0 +1,19 @@ +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Thread = require "luan:Thread.luan" +local Time = require "luan:Time.luan" + + +local globals = Thread.global_map("globals") +globals.i = 0 + +local function inc() + globals.i = globals.i + 1 +end + +Thread.schedule( inc, {repeating_delay=Time.period{minutes=1}} ) + +return function() + Io.stdout = Http.response.text_writer() + %>hi <%=globals.i%><% +end
--- 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