Browse Source

Refactor SSH command execution to improve command quoting and enhance readability

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

13
scripts/auto-boot-ollama-host.lua

@ -120,7 +120,7 @@ local function ssh(command, user, host, port, identity_file)
table.insert(pieces, dest) table.insert(pieces, dest)
-- Pass remote command as provided; caller is responsible for proper quoting. -- Pass remote command as provided; caller is responsible for proper quoting.
table.insert(pieces, command) table.insert(pieces, " -- " .. command)
-- Join with spaces for os.execute -- Join with spaces for os.execute
local function join(args) local function join(args)
@ -168,19 +168,12 @@ local function main()
end end
end end
-- Optional wait (kept commented for minimal parity)
-- if port_is_up(OLLAMA_HOST, OLLAMA_PORT, UP_WAIT_TIMEOUT) then
-- log("Ollama reachable again.")
-- else
-- log("Timeout waiting for Ollama.")
-- end
log("Waiting for SSH to become reachable...") log("Waiting for SSH to become reachable...")
if port_is_up(OLLAMA_HOST, SSH_PORT, 60) then if port_is_up(OLLAMA_HOST, SSH_PORT, 60) then
log("SSH is reachable. Starting ollama service...") log("SSH is reachable. Starting ollama service...")
socket.sleep(2) socket.sleep(2)
ssh('wsl.exe -d Debian -- sudo sh -lc "systemctl enable ollama && systemctl start ollama"', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) 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 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)
@ -194,7 +187,7 @@ local function main()
if line:find(FINISH_PATTERN, 1, true) ~= nil and powered_on == true then if line:find(FINISH_PATTERN, 1, true) ~= nil and powered_on == true then
log(("Detected finish pattern: %q"):format(FINISH_PATTERN)) log(("Detected finish pattern: %q"):format(FINISH_PATTERN))
log("Shutting down Ollama host to save power...") log("Shutting down Ollama host to save power...")
ssh('wsl.exe -d Debian -- sudo sh -lc "systemctl disable ollama && 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) socket.sleep(5)
powered_on = false powered_on = false

Loading…
Cancel
Save