From 24014fd1216a00426d843d5cdffc98462d093aa1 Mon Sep 17 00:00:00 2001 From: cediackermann Date: Fri, 24 Apr 2026 11:28:08 +0200 Subject: [PATCH] Expose Ollama on all network interfaces via launchd agent By default Ollama only binds to 127.0.0.1, making it unreachable from other devices. Install a launchd plist that sets OLLAMA_HOST=0.0.0.0 so the Ollama device is discoverable by the Onyx device on the network. The agent also auto-starts Ollama at login. --- steps/step_ollama.sh | 62 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/steps/step_ollama.sh b/steps/step_ollama.sh index df15ffb..2af17a0 100755 --- a/steps/step_ollama.sh +++ b/steps/step_ollama.sh @@ -1,6 +1,9 @@ #!/bin/bash # Step: Install and start Ollama. Source common.sh before sourcing this file. +# Launchd plist that starts Ollama on all interfaces at login. +OLLAMA_PLIST="$HOME/Library/LaunchAgents/com.ollama.serve.plist" + install_ollama() { print_step "Installing Ollama" @@ -13,18 +16,55 @@ install_ollama() { print_success "Ollama installed successfully" fi - print_warning "Starting Ollama service..." - if ! pgrep -x "ollama" > /dev/null; then - nohup ollama serve > /tmp/ollama.log 2>&1 & - sleep 3 + # Register Ollama as a launchd agent so it: + # - starts automatically at login + # - listens on all interfaces (0.0.0.0) so other devices can reach it + print_warning "Configuring Ollama to listen on all network interfaces..." + mkdir -p "$HOME/Library/LaunchAgents" + cat > "$OLLAMA_PLIST" < + + + + Label + com.ollama.serve + ProgramArguments + + /usr/local/bin/ollama + serve + + EnvironmentVariables + + OLLAMA_HOST + 0.0.0.0:11434 + + RunAtLoad + + KeepAlive + + StandardOutPath + /tmp/ollama.log + StandardErrorPath + /tmp/ollama.log + + +EOF - if pgrep -x "ollama" > /dev/null; then - print_success "Ollama service started" - else - print_warning "Ollama service may not have started properly" - echo " Check logs at: /tmp/ollama.log" - fi + # Stop any existing instance first so the new config takes effect + if pgrep -x "ollama" > /dev/null; then + print_warning "Restarting Ollama with network binding..." + launchctl unload "$OLLAMA_PLIST" 2>/dev/null || true + pkill -x ollama 2>/dev/null || true + sleep 1 + fi + + launchctl load "$OLLAMA_PLIST" + sleep 3 + + if pgrep -x "ollama" > /dev/null; then + print_success "Ollama service started (listening on 0.0.0.0:11434)" else - print_success "Ollama service already running" + print_warning "Ollama service may not have started properly" + echo " Check logs at: /tmp/ollama.log" fi }