Browse Source

Add FINISH_PATTERN detection and adjust shutdown logic for Ollama host

main
Bastian (BaM) 3 months ago
parent
commit
1424458bcb
  1. 13
      scripts/auto-boot-ollama-host.lua

13
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()

Loading…
Cancel
Save