Files
users/scripts/launch_local.sh

72 lines
1.8 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/zsh
# 神射手 本地版启动脚本 - 纯 shell无 Python/tkinter 依赖
PROJECT="/Users/karuo/Documents/开发/2、私域银行/神射手"
export PATH="/opt/homebrew/bin:/usr/local/bin:${HOME}/.volta/bin:${PATH}"
[ -d "${HOME}/.fnm/current/bin" ] && export PATH="${HOME}/.fnm/current/bin:${PATH}"
notify() { osascript -e "display notification \"$1\" with title \"神射手\"" 2>/dev/null; }
open_url() { open "$1" 2>/dev/null || true; }
cd "$PROJECT" || { notify "项目路径不存在"; exit 1; }
# 1. Ollama
notify "检查本地大模型..."
if ! curl -s --connect-timeout 2 "http://localhost:11434/api/tags" >/dev/null 2>&1; then
notify "正在启动 Ollama..."
open -a Ollama 2>/dev/null || true
for i in {1..45}; do
curl -s --connect-timeout 2 "http://localhost:11434/api/tags" >/dev/null 2>&1 && break
sleep 1
done
fi
notify "Ollama 就绪"
# 2. Docker
notify "检查 Docker..."
open -a Docker 2>/dev/null || true
for i in {1..60}; do
docker info >/dev/null 2>&1 && break
sleep 2
done
notify "Docker 就绪"
# 3. MongoDB
notify "启动 MongoDB..."
docker start datacenter_mongodb 2>/dev/null || true
sleep 3
notify "MongoDB 就绪"
# 4. 若 3117 已监听,直接打开
if lsof -i :3117 -sTCP:LISTEN >/dev/null 2>&1; then
notify "服务已在运行,打开浏览器"
open_url "http://localhost:3117"
exit 0
fi
# 5. 启动 pnpm dev后台
notify "启动神射手开发服务..."
if command -v pnpm >/dev/null 2>&1; then
pnpm dev &
else
npm run dev &
fi
PID=$!
trap "kill $PID 2>/dev/null; exit" EXIT INT TERM
# 6. 等待 3117
for i in {1..90}; do
lsof -i :3117 -sTCP:LISTEN >/dev/null 2>&1 && break
sleep 1
done
# 7. 打开浏览器
notify "神射手已启动"
open_url "http://localhost:3117"
echo "神射手已启动: http://localhost:3117"
echo "关闭此窗口将停止服务"
echo ""
# 8. 保持运行
wait $PID