From 11cc5779b59e91d6a80a48066eb6507427141e73 Mon Sep 17 00:00:00 2001 From: "Bastian (BaM)" Date: Sun, 14 Sep 2025 14:23:46 +0200 Subject: [PATCH] Add WOL state tracking to manage shutdown logic for Ollama host --- scripts/auto-boot-ollama-host.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/auto-boot-ollama-host.lua b/scripts/auto-boot-ollama-host.lua index 8267b13..9a9c9bd 100644 --- a/scripts/auto-boot-ollama-host.lua +++ b/scripts/auto-boot-ollama-host.lua @@ -147,6 +147,7 @@ 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 powered_on = false while true do @@ -160,6 +161,7 @@ local function main() log(("Sending WOL to %s via %s:%d"):format(WOL_MAC, WOL_BCAST, WOL_PORT)) local ok, err = send_wol(WOL_MAC, WOL_BCAST, WOL_PORT) if ok then + powered_on = true log(("Sucessfully sent WOL to %s via %s:%d"):format(WOL_MAC, WOL_BCAST, WOL_PORT)) else log("WOL failed: " .. tostring(err)) @@ -189,12 +191,13 @@ local function main() end end - if line:find(FINISH_PATTERN, 1, true) ~= nil then + if line:find(FINISH_PATTERN, 1, true) ~= nil and powered_on == true 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) socket.sleep(5) + powered_on = false break end end