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.
This commit is contained in:
cediackermann 2026-04-24 11:28:08 +02:00
parent 5b895a19b4
commit 24014fd121

View file

@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
# Step: Install and start Ollama. Source common.sh before sourcing this file. # 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() { install_ollama() {
print_step "Installing Ollama" print_step "Installing Ollama"
@ -13,18 +16,55 @@ install_ollama() {
print_success "Ollama installed successfully" print_success "Ollama installed successfully"
fi fi
print_warning "Starting Ollama service..." # Register Ollama as a launchd agent so it:
if ! pgrep -x "ollama" > /dev/null; then # - starts automatically at login
nohup ollama serve > /tmp/ollama.log 2>&1 & # - 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" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ollama.serve</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/ollama</string>
<string>serve</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>OLLAMA_HOST</key>
<string>0.0.0.0:11434</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/ollama.log</string>
<key>StandardErrorPath</key>
<string>/tmp/ollama.log</string>
</dict>
</plist>
EOF
# 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 sleep 3
if pgrep -x "ollama" > /dev/null; then if pgrep -x "ollama" > /dev/null; then
print_success "Ollama service started" print_success "Ollama service started (listening on 0.0.0.0:11434)"
else else
print_warning "Ollama service may not have started properly" print_warning "Ollama service may not have started properly"
echo " Check logs at: /tmp/ollama.log" echo " Check logs at: /tmp/ollama.log"
fi fi
else
print_success "Ollama service already running"
fi
} }