Add desktop session detection to auto-boot-ollama-host script
Implement a new module for checking if the user is logged into a Windows desktop session. The script now skips Ollama startup and shutdown if the user is currently logged in, preventing interruptions. Update README to reflect new features and module structure.
This commit is contained in:
@@ -13,11 +13,23 @@ local utils = require("utils")
|
||||
local network = require("network")
|
||||
local ssh = require("ssh")
|
||||
local ollama_manager = require("ollama_manager")
|
||||
local session_check = require("session_check")
|
||||
|
||||
-- Handle error pattern detection and recovery
|
||||
local function handle_error_pattern(config, powered_on)
|
||||
utils.log(("Detected EHOSTUNREACH for Ollama (%s:%d)."):format(config.OLLAMA_HOST, config.OLLAMA_PORT))
|
||||
|
||||
-- Check if user is currently logged into a desktop session
|
||||
utils.log("Checking if user is currently logged into desktop session...")
|
||||
local user_logged_in = session_check.is_user_logged_in(config)
|
||||
|
||||
if user_logged_in then
|
||||
utils.log(("User '%s' is currently logged into a desktop session. Skipping Ollama startup to avoid interruption."):format(config.SSH_USER))
|
||||
return powered_on -- Return current powered_on state without changes
|
||||
end
|
||||
|
||||
utils.log(("User '%s' is not logged into a desktop session. Proceeding with Ollama startup."):format(config.SSH_USER))
|
||||
|
||||
-- Send Wake-on-LAN if configured
|
||||
if config.WOL_MAC ~= "" then
|
||||
utils.log(("Sending WOL to %s via %s:%d"):format(config.WOL_MAC, config.WOL_BCAST, config.WOL_PORT))
|
||||
@@ -40,6 +52,17 @@ end
|
||||
-- Handle finish pattern detection and shutdown
|
||||
local function handle_finish_pattern(config)
|
||||
utils.log(("Detected finish pattern: %q"):format(config.FINISH_PATTERN))
|
||||
|
||||
-- Check if user is currently logged into a desktop session
|
||||
utils.log("Checking if user is currently logged into desktop session before shutdown...")
|
||||
local user_logged_in = session_check.is_user_logged_in(config)
|
||||
|
||||
if user_logged_in then
|
||||
utils.log(("User '%s' is currently logged into a desktop session. Skipping shutdown to avoid interruption."):format(config.SSH_USER))
|
||||
return -- Exit without shutting down
|
||||
end
|
||||
|
||||
utils.log(("User '%s' is not logged into a desktop session. Proceeding with shutdown."):format(config.SSH_USER))
|
||||
ollama_manager.stop_service_and_shutdown(config)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user