Refactor log monitoring loop to continuously check for error and finish patterns, enhancing Ollama service management

This commit is contained in:
Bastian (BaM)
2025-09-14 14:20:20 +02:00
parent adff6a42d1
commit e743f61aef

View File

@@ -147,8 +147,10 @@ local function main()
log(("Looking for pattern: %q"):format(ERROR_PATTERN))
local cmd = ("docker logs -f --since %q %q 2>&1"):format(SINCE, CONTAINER_NAME)
local fh = assert(io.popen(cmd, "r"))
while true do
local fh = assert(io.popen(cmd, "r"))
for line in fh:lines() do
-- Plain substring match (no regex)
if line:find(ERROR_PATTERN, 1, true) ~= nil then
@@ -180,6 +182,7 @@ local function main()
if (port_is_up(OLLAMA_HOST, OLLAMA_PORT, 90)) then
log("Ollama service is reachable again.")
socket.sleep(30)
break
else
log("Timeout waiting for Ollama service to come up after SSH command.")
end
@@ -191,6 +194,8 @@ local function main()
log("Shutting down Ollama host to save power...")
ssh("wsl.exe -d Debian -- 'sudo systemctl disable ollama && sudo systemctl stop ollama'", "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE)
ssh("shutdown.exe /s /t 0", "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE)
socket.sleep(5)
break
end
end
@@ -198,4 +203,6 @@ local function main()
log("Log stream ended.")
end
end
main()