Files
openclaw-ollama-toolcall-proxy/install-launchagent.sh
hotwa ebd73e1c69 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>
2026-03-22 16:02:40 +08:00

108 lines
2.9 KiB
Bash
Executable File
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/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