Add WOL state tracking to manage shutdown logic for Ollama host
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user