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:
parent
5b895a19b4
commit
24014fd121
1 changed files with 51 additions and 11 deletions
|
|
@ -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
|
||||||
sleep 3
|
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
|
||||||
|
|
||||||
if pgrep -x "ollama" > /dev/null; then
|
# Stop any existing instance first so the new config takes effect
|
||||||
print_success "Ollama service started"
|
if pgrep -x "ollama" > /dev/null; then
|
||||||
else
|
print_warning "Restarting Ollama with network binding..."
|
||||||
print_warning "Ollama service may not have started properly"
|
launchctl unload "$OLLAMA_PLIST" 2>/dev/null || true
|
||||||
echo " Check logs at: /tmp/ollama.log"
|
pkill -x ollama 2>/dev/null || true
|
||||||
fi
|
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
|
else
|
||||||
print_success "Ollama service already running"
|
print_warning "Ollama service may not have started properly"
|
||||||
|
echo " Check logs at: /tmp/ollama.log"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue