From 1424458bcb69be7ceda990fc76f1628c3fdba09b Mon Sep 17 00:00:00 2001 From: "Bastian (BaM)" Date: Sun, 14 Sep 2025 14:15:49 +0200 Subject: [PATCH] Add FINISH_PATTERN detection and adjust shutdown logic for Ollama host --- scripts/auto-boot-ollama-host.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/auto-boot-ollama-host.lua b/scripts/auto-boot-ollama-host.lua index a6f2d6e..8bf3388 100644 --- a/scripts/auto-boot-ollama-host.lua +++ b/scripts/auto-boot-ollama-host.lua @@ -43,6 +43,7 @@ local ERROR_PATTERN = getenv( "ERROR_PATTERN", ("connect EHOSTUNREACH %s:%d"):format(OLLAMA_HOST, OLLAMA_PORT) ) +local FINISH_PATTERN = getenv("FINISH_PATTERN", "[DEBUG] Finished fetching. Found 0 documents.") -- e.g. "Server started" -- Optional Wake-on-LAN local WOL_MAC = getenv("WOL_MAC", "") -- e.g. "AA:BB:CC:DD:EE:FF" @@ -178,15 +179,19 @@ local function main() ssh("wsl.exe -d Debian -- 'sudo systemctl enable ollama && sudo systemctl start ollama'", "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) if (port_is_up(OLLAMA_HOST, OLLAMA_PORT, 90)) then log("Ollama service is reachable again.") - socket.sleep(180) - 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(2) else log("Timeout waiting for Ollama service to come up after SSH command.") end end end + + if line:find(FINISH_PATTERN, 1, true) ~= nil then + log(("Detected finish pattern: %q"):format(FINISH_PATTERN)) + 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) + end end fh:close()