diff --git a/scripts/auto-boot-ollama-host.lua b/scripts/auto-boot-ollama-host.lua index c1243b5..4474fe9 100644 --- a/scripts/auto-boot-ollama-host.lua +++ b/scripts/auto-boot-ollama-host.lua @@ -24,7 +24,7 @@ local ERROR_PATTERN = getenv( -- Optional Wake-on-LAN local WOL_MAC = getenv("WOL_MAC", "") -- e.g. "AA:BB:CC:DD:EE:FF" -local WOL_BCAST = getenv("WOL_BCAST", "255.255.255.255") +local WOL_BCAST = getenv("WOL_BCAST", "192.168.222.255") local WOL_PORT = tonumber(getenv("WOL_PORT", "9")) -- Optional: wait for service to come up (kept commented to stay minimal) @@ -46,14 +46,26 @@ local function send_wol(mac_str, bcast_ip, port) local mb = mac_to_bytes(mac_str) if not mb then return false, "invalid MAC" end local packet = string.rep(string.char(0xFF), 6) .. mb:rep(16) + local udp = assert(socket.udp()) udp:settimeout(2) - pcall(function() assert(udp:setoption("broadcast", true)) end) + + -- Optional: bind to a specific source IP (helps in host network with multi-NIC) + local WOL_SRC_IP = os.getenv("WOL_SRC_IP") + if WOL_SRC_IP and WOL_SRC_IP ~= "" then + assert(udp:setsockname(WOL_SRC_IP, 0)) + end + + -- IMPORTANT: must be true or Linux will return EACCES on broadcast sendto() + assert(udp:setoption("broadcast", true)) + local ok, err = udp:sendto(packet, bcast_ip, port) udp:close() - return ok ~= nil, err + if not ok then return false, err end + return true end + -- Kept for reference; not used to keep parity with your minimal bash -- local function port_is_up(host, port, timeout_sec) -- local deadline = socket.gettime() + (timeout_sec or 1) diff --git a/scripts/auto-boot-ollama-host.sh b/scripts/auto-boot-ollama-host.sh index 631e2ae..52575cc 100644 --- a/scripts/auto-boot-ollama-host.sh +++ b/scripts/auto-boot-ollama-host.sh @@ -12,7 +12,7 @@ OLLAMA_PORT="${OLLAMA_PORT:-11434}" ERROR_PATTERN="${ERROR_PATTERN:-Error: \\[ERROR\\] Document analysis failed: connect EHOSTUNREACH ${OLLAMA_HOST}:${OLLAMA_PORT}}" WOL_MAC="${WOL_MAC:-}" -WOL_BCAST="${WOL_BCAST:-255.255.255.255}" +WOL_BCAST="${WOL_BCAST:-192.168.222.255}" WOL_PORT="${WOL_PORT:-9}" DOCKER_CLI="${DOCKER_CLI:-docker}" # docker CLI binary name