feat: add macOS LaunchAgent install/uninstall scripts
- Add install-launchagent.sh for auto-start on boot - Add uninstall-launchagent.sh for service removal - Update README.md with deployment instructions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
62
README.md
62
README.md
@@ -78,3 +78,65 @@ curl -s http://127.0.0.1:11435/api/chat \
|
||||
npm run test
|
||||
\`\`\`
|
||||
将会进行 `xml-toolcall` 解析用例和端到端整合测试。
|
||||
|
||||
---
|
||||
|
||||
## macOS 开机自启动部署
|
||||
|
||||
本项目提供了 LaunchAgent 安装脚本,可将代理服务配置为开机自动启动。
|
||||
|
||||
### 安装步骤
|
||||
|
||||
1. 确保已完成前面的「获取代码与安装」和「环境配置」步骤
|
||||
|
||||
2. 运行安装脚本:
|
||||
\`\`\`bash
|
||||
./install-launchagent.sh
|
||||
\`\`\`
|
||||
|
||||
3. 验证服务状态:
|
||||
\`\`\`bash
|
||||
# 检查服务是否运行
|
||||
launchctl list com.openclaw.ollama-proxy
|
||||
|
||||
# 测试代理响应
|
||||
curl http://127.0.0.1:11435/
|
||||
\`\`\`
|
||||
|
||||
### 常用命令
|
||||
|
||||
| 操作 | 命令 |
|
||||
|------|------|
|
||||
| 查看状态 | `launchctl list com.openclaw.ollama-proxy` |
|
||||
| 停止服务 | `launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.openclaw.ollama-proxy.plist` |
|
||||
| 启动服务 | `launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.openclaw.ollama-proxy.plist` |
|
||||
| 查看日志 | `tail -f ~/Library/Logs/OpenClawOllamaProxy/stdout.log` |
|
||||
| 查看错误日志 | `tail -f ~/Library/Logs/OpenClawOllamaProxy/stderr.log` |
|
||||
|
||||
### 卸载服务
|
||||
|
||||
\`\`\`bash
|
||||
./uninstall-launchagent.sh
|
||||
\`\`\`
|
||||
|
||||
### 多机器部署
|
||||
|
||||
如需在多台机器上部署,只需在每台机器上执行以下步骤:
|
||||
|
||||
\`\`\`bash
|
||||
# 1. 克隆代码
|
||||
git clone ssh://git@gitea.jmsu.top:2222/lingyuzeng/openclaw-ollama-toolcall-proxy.git
|
||||
cd openclaw-ollama-toolcall-proxy
|
||||
|
||||
# 2. 安装依赖
|
||||
npm install
|
||||
|
||||
# 3. 配置环境变量
|
||||
cp .env.example .env
|
||||
# 编辑 .env 配置目标 Ollama 地址
|
||||
|
||||
# 4. 安装开机自启动服务
|
||||
./install-launchagent.sh
|
||||
\`\`\`
|
||||
|
||||
日志位置:`~/Library/Logs/OpenClawOllamaProxy/`
|
||||
|
||||
107
install-launchagent.sh
Executable file
107
install-launchagent.sh
Executable file
@@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
|
||||
# OpenClaw Ollama Toolcall Proxy - macOS LaunchAgent 安装脚本
|
||||
# 将服务配置为开机自动启动
|
||||
|
||||
set -e
|
||||
|
||||
# 配置
|
||||
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SERVICE_NAME="com.openclaw.ollama-proxy"
|
||||
PLIST_PATH="$HOME/Library/LaunchAgents/${SERVICE_NAME}.plist"
|
||||
LOG_DIR="$HOME/Library/Logs/OpenClawOllamaProxy"
|
||||
|
||||
# 颜色输出
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}=== OpenClaw Ollama Proxy LaunchAgent 安装 ===${NC}"
|
||||
echo ""
|
||||
|
||||
# 检查 Node.js
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo -e "${RED}错误: 未找到 Node.js,请先安装 Node.js${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 获取 node 和 npx 的完整路径
|
||||
NODE_PATH="$(which node)"
|
||||
NPX_PATH="$(which npx)"
|
||||
|
||||
echo -e "${YELLOW}项目目录:${NC} $PROJECT_DIR"
|
||||
echo -e "${YELLOW}Node 路径:${NC} $NODE_PATH"
|
||||
echo -e "${YELLOW}NPX 路径:${NC} $NPX_PATH"
|
||||
echo ""
|
||||
|
||||
# 创建日志目录
|
||||
mkdir -p "$LOG_DIR"
|
||||
echo -e "${GREEN}✓${NC} 创建日志目录: $LOG_DIR"
|
||||
|
||||
# 构建 plist 文件
|
||||
cat > "$PLIST_PATH" << 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>${SERVICE_NAME}</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>${NPX_PATH}</string>
|
||||
<string>tsx</string>
|
||||
<string>${PROJECT_DIR}/src/index.ts</string>
|
||||
</array>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>${PROJECT_DIR}</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>${LOG_DIR}/stdout.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>${LOG_DIR}/stderr.log</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PATH</key>
|
||||
<string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✓${NC} 生成 plist: $PLIST_PATH"
|
||||
|
||||
# 卸载旧服务(如果存在)
|
||||
if launchctl list "$SERVICE_NAME" &> /dev/null; then
|
||||
launchctl bootout gui/$(id -u) "$PLIST_PATH" 2>/dev/null || true
|
||||
echo -e "${GREEN}✓${NC} 卸载旧服务"
|
||||
fi
|
||||
|
||||
# 加载新服务
|
||||
launchctl bootstrap gui/$(id -u) "$PLIST_PATH"
|
||||
echo -e "${GREEN}✓${NC} 加载新服务"
|
||||
|
||||
# 等待服务启动
|
||||
sleep 1
|
||||
|
||||
# 检查服务状态
|
||||
if launchctl list "$SERVICE_NAME" &> /dev/null; then
|
||||
echo ""
|
||||
echo -e "${GREEN}=== 安装成功 ===${NC}"
|
||||
echo ""
|
||||
echo "服务名称: $SERVICE_NAME"
|
||||
echo "监听地址: http://0.0.0.0:11435"
|
||||
echo "日志目录: $LOG_DIR"
|
||||
echo ""
|
||||
echo "常用命令:"
|
||||
echo " 查看状态: launchctl list $SERVICE_NAME"
|
||||
echo " 停止服务: launchctl bootout gui/\$(id -u) $PLIST_PATH"
|
||||
echo " 启动服务: launchctl bootstrap gui/\$(id -u) $PLIST_PATH"
|
||||
echo " 查看日志: tail -f $LOG_DIR/stdout.log"
|
||||
else
|
||||
echo -e "${RED}服务启动失败,请检查日志: $LOG_DIR/stderr.log${NC}"
|
||||
exit 1
|
||||
fi
|
||||
37
uninstall-launchagent.sh
Executable file
37
uninstall-launchagent.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# OpenClaw Ollama Toolcall Proxy - macOS LaunchAgent 卸载脚本
|
||||
|
||||
set -e
|
||||
|
||||
SERVICE_NAME="com.openclaw.ollama-proxy"
|
||||
PLIST_PATH="$HOME/Library/LaunchAgents/${SERVICE_NAME}.plist"
|
||||
LOG_DIR="$HOME/Library/Logs/OpenClawOllamaProxy"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo -e "${YELLOW}=== OpenClaw Ollama Proxy LaunchAgent 卸载 ===${NC}"
|
||||
echo ""
|
||||
|
||||
# 停止并卸载服务
|
||||
if launchctl list "$SERVICE_NAME" &> /dev/null; then
|
||||
launchctl bootout gui/$(id -u) "$PLIST_PATH"
|
||||
echo -e "${GREEN}✓${NC} 停止并卸载服务"
|
||||
else
|
||||
echo -e "${YELLOW}服务未运行${NC}"
|
||||
fi
|
||||
|
||||
# 删除 plist 文件
|
||||
if [ -f "$PLIST_PATH" ]; then
|
||||
rm "$PLIST_PATH"
|
||||
echo -e "${GREEN}✓${NC} 删除 plist 文件: $PLIST_PATH"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}=== 卸载完成 ===${NC}"
|
||||
echo ""
|
||||
echo "日志目录保留在: $LOG_DIR"
|
||||
echo "如需删除日志: rm -rf $LOG_DIR"
|
||||
Reference in New Issue
Block a user