Refactor log monitoring loop to continuously check for error and finish patterns, enhancing Ollama service management
This commit is contained in:
@@ -147,8 +147,10 @@ local function main()
|
|||||||
log(("Looking for pattern: %q"):format(ERROR_PATTERN))
|
log(("Looking for pattern: %q"):format(ERROR_PATTERN))
|
||||||
|
|
||||||
local cmd = ("docker logs -f --since %q %q 2>&1"):format(SINCE, CONTAINER_NAME)
|
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
|
for line in fh:lines() do
|
||||||
-- Plain substring match (no regex)
|
-- Plain substring match (no regex)
|
||||||
if line:find(ERROR_PATTERN, 1, true) ~= nil then
|
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
|
if (port_is_up(OLLAMA_HOST, OLLAMA_PORT, 90)) then
|
||||||
log("Ollama service is reachable again.")
|
log("Ollama service is reachable again.")
|
||||||
socket.sleep(30)
|
socket.sleep(30)
|
||||||
|
break
|
||||||
else
|
else
|
||||||
log("Timeout waiting for Ollama service to come up after SSH command.")
|
log("Timeout waiting for Ollama service to come up after SSH command.")
|
||||||
end
|
end
|
||||||
@@ -191,11 +194,15 @@ local function main()
|
|||||||
log("Shutting down Ollama host to save power...")
|
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("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)
|
ssh("shutdown.exe /s /t 0", "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE)
|
||||||
|
socket.sleep(5)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fh:close()
|
fh:close()
|
||||||
log("Log stream ended.")
|
log("Log stream ended.")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user