macOS 后台服务管家
简介
基于 macOS launchd 的守护进程管理器,支持程序后台化与自动重启,无需 sudo,代码透明,适合开发环境长期运行服务。
原始描述
Manage macOS launchd user agents to start, stop, restart, check status, and access logs of persistent background services without sudo.
通过你的 Agent 添加
点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。
或者手动安装
包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。
技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。
中文使用说明 来自收录源
核心功能
toolguard-daemon-control 是一套 macOS 专用的后台服务管理方案,将任意可执行文件注册为 launchd 用户代理(User Agent)。核心功能包括:
- 服务安装:通过
install.sh生成 plist 配置文件并启动服务,支持自定义工作目录和环境变量 - 生命周期管理:提供
start/stop/restart/status/uninstall全套操作 - 日志集成:自动将 stdout/stderr 重定向到
~/Library/Logs/toolguard/<name>/ - 故障自愈:配置
KeepAlive = true实现崩溃后自动重启
显著优点
- 零权限设计:完全在用户目录(
~/Library/LaunchAgents)操作,无需 sudo,降低误操作风险 - Unix 哲学践行:功能单一聚焦,6 个脚本各司其职,无冗余功能
- 防御性编程:全脚本使用
set -euo pipefail,错误处理严格 - 透明可审计:纯 Bash 实现,零第三方依赖,代码可读性高
- 资源隔离:服务以当前用户身份运行,与系统服务域分离
局限性与注意事项
| 局限 | 说明 |
|---|---|
| 平台锁定 | 完全依赖 macOS launchd,Linux/Windows 无法使用 |
| Go 开发限制 | 不支持直接使用 go run,需先编译为二进制 |
| eval 隐患 | install.sh 使用 eval echo 展开路径,存在潜在注入风险(低风险) |
| 无服务依赖管理 | 不支持声明服务间的启动依赖关系 |
适用人群
- macOS 开发者需要将自定义工具(代理服务器、定时任务、开发服务)转为常驻后台服务
- 需要替代
nohup、&后台运行的场景,要求崩溃自动重启 - 不熟悉 launchd plist 语法,希望用命令行快速管理服务的用户
常规风险
- 输入验证不足:service-name 未做字符集校验,特殊字符可能导致 plist 生成异常
- 路径注入:
--workdir参数经 eval 展开,若来源不可控存在命令注入可能 - 残留日志:uninstall 不清理日志目录,长期运行可能累积磁盘占用
安全结论
安全认证评分 95/S 级,来源为 GitHub 组织 openclaw(T2 可信度)。代码质量良好,操作范围严格受限,无网络通信与敏感数据收集。建议在隔离环境验证后投入生产使用。
技能正文
name: toolguard-daemon-control description: Manage long-running processes as macOS launchd services. Use when asked to start, stop, restart, check status of, or manage background services/daemons. Handles launchd plist creation, service lifecycle, and log access. Use this instead of background exec for any process that should persist beyond the current session.
toolguard-daemon-control
Manage any executable as a persistent macOS launchd user agent.
Overview
Services are installed as ~/Library/LaunchAgents/ai.toolguard.<name>.plist and run as user-level launch agents. They auto-restart on failure and log to ~/Library/Logs/toolguard/.
Scripts
All scripts are in scripts/ relative to this skill's directory. Run them with bash.
install.sh — Create and start a service
bash scripts/install.sh <service-name> <command> [args...] [--workdir <dir>] [--env KEY=VALUE ...]
service-name: Short identifier (e.g.,toolguard-proxy). Used in plist filename and log paths.command: Absolute path to the executable.args: Arguments passed to the command.--workdir <dir>: Working directory for the process (default:$HOME).--env KEY=VALUE: Environment variables (repeatable).
Example:
bash scripts/install.sh toolguard-proxy /usr/local/go/bin/go run ./cmd/server --config toolguard.dev.yaml --workdir ~/Documents/toolguard
uninstall.sh — Stop and remove a service
bash scripts/uninstall.sh <service-name>
Unloads the service and removes the plist file. Logs are preserved.
status.sh — Check service status
bash scripts/status.sh [service-name]
Without arguments, lists all ai.toolguard.* services. With a name, shows detailed status for that service.
logs.sh — View service logs
bash scripts/logs.sh <service-name> [--follow] [--lines <n>]
Shows stdout and stderr logs. Default: last 50 lines.
list.sh — List all managed services
bash scripts/list.sh
Lists all installed ai.toolguard.* services with their running state.
Notes
- Services run as the current user (no sudo required).
- Services auto-restart on crash (
KeepAlive = true). - To run a Go project, use the compiled binary path or wrap in a shell script — launchd does not support
go rundirectly. Usego buildfirst, then point to the binary. - Log directory:
~/Library/Logs/toolguard/<service-name>/ - Plist location:
~/Library/LaunchAgents/ai.toolguard.<service-name>.plist
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。