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.
2.5 KiB
2.5 KiB
Auto-Boot Ollama Host - Refactored Structure
This directory contains the refactored version of the auto-boot-ollama-host script, split into multiple modules for better maintainability and structure.
File Structure
Main Script
auto-boot-ollama-host.lua- Original monolithic scriptauto-boot-ollama-host-refactored.lua- New modular main script
Modules
config.lua
Handles all environment variable configuration with sensible defaults:
- Docker configuration (container name, since time)
- Ollama service configuration (host, port)
- SSH configuration (port, user, identity file)
- Pattern configuration (error and finish patterns)
- Wake-on-LAN configuration
utils.lua
Provides utility functions:
log(msg)- Timestamped logginggetenv(name, def)- Environment variable with default
network.lua
Network-related functionality:
port_is_up(host, port, timeout)- Check if TCP port is accessiblesend_wol(mac, bcast_ip, port)- Send Wake-on-LAN magic packet
ssh.lua
SSH command execution:
execute(command, user, host, port, identity_file)- Execute remote SSH commandexecute_with_output(command, user, host, port, identity_file)- Execute SSH command and return output
ollama_manager.lua
Ollama service management:
start_service(config)- Start Ollama service via SSHstop_service_and_shutdown(config)- Stop service and shutdown host
session_check.lua
Windows desktop session detection:
is_user_logged_in_enhanced(config)- Check if user is logged into desktop session
Benefits of Refactoring
- Separation of Concerns: Each module has a single responsibility
- Reusability: Modules can be reused in other projects
- Testability: Individual modules can be unit tested
- Maintainability: Easier to locate and modify specific functionality
- Readability: Clear structure and organization
- Configuration: Centralized configuration management
New Features
Desktop Session Detection
The refactored version now includes Windows desktop session detection:
- Checks if the SSH_USER is currently logged into a Windows desktop session
- If user is logged in, skips Ollama startup/shutdown to avoid interruption
- If user is not logged in, proceeds with normal operation
Usage
To use the refactored version, simply run:
lua auto-boot-ollama-host.lua
The refactored version maintains full compatibility with the original script while providing better structure and maintainability.