mac 使用 launchctl 实现每次登录系统时 frpc 就会自动启动

测试

测试正常是否可以启动

bash 复制代码
/Users/zhangbaoxing/SoftWare/frp_0.61.0_darwin_arm64/frpc -c /Users/zhangbaoxing/SoftWare/frp_0.61.0_darwin_arm64/frpc.toml

步骤

launchctl 是根据plist文件的信息来启动任务的,所以我们要加一个frp的plist

mac系统一般提供两种自启方式,

1.是跟随系统启动就开始运行,无论用户有没有登陆账号。2.只有用户登陆了账号进入桌面才开始自动运行

  • /Library/LaunchDaemons --> 只要系统启动,无论用户有没有登陆系统也会被执行
  • /Library/LaunchAgents --> 只有用户登陆系统后才会被执行

这里以设置用户登陆系统后才会被执行为例

bash 复制代码
# 首先创建 LaunchAgents 目录(如果不存在):
mkdir -p ~/Library/LaunchAgents
# 创建 plist 文件
vim ~/Library/LaunchAgents/frpc.plist

编辑文件frpc.plist:

bash 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>frpc</string>
<key>ProgramArguments</key>
<array>
<string>/Users/zhangbaoxing/SoftWare/frp_0.61.0_darwin_arm64/frpc</string>
<string>-c</string>
<string>/Users/zhangbaoxing/SoftWare/frp_0.61.0_darwin_arm64/frpc.toml</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
bash 复制代码
# 设置权限 加载服务
chmod 644 ~/Library/LaunchAgents/frpc.plist
launchctl load ~/Library/LaunchAgents/frpc.plist

# 检查服务是否正在运行
launchctl list | grep frpc

# 停止服务
launchctl unload ~/Library/LaunchAgents/frpc.plist

launchctl常用命令

bash 复制代码
# 加载任务, -w 会将plist文件中无效的key覆盖掉,建议加上
launchctl load -w frpc.plist

# 删除任务
launchctl unload -w frpc.plist

# 查看任务列表, 使用 grep '任务部分名字' 过滤
launchctl list | grep 'frpc'

# 开始任务
launchctl start frpc.plist

# 结束任务
launchctl stop frpc.plist
相关推荐
阿正的梦工坊30 分钟前
在Mac电脑上如何显示点(.)开头的隐藏文件
macos
AI-小柒1 小时前
DataEyes 聚合平台 + Claude Code Max 编程实战
android·开发语言·人工智能·windows·python·macos·adb
I'm Jie4 小时前
MacOS 使用 pyenv + brew 优雅管理 Python 多版本环境
python·macos·pyenv
李小白杂货铺4 小时前
网络测速脚本(MacOS和Linux平台可用)
linux·macos·脚本·curl·ping·网络测速·网络测速脚本
钱多多_qdd5 小时前
第一次使用mac,安装java相关的东西
java·python·macos
xiegwei5 小时前
mac直接拔掉u盘之后不识别
macos
AxureMost6 小时前
Seelen UI 桌面美化工具(仿MAC交互)
macos·ui·交互
小手智联老徐6 小时前
在 macOS 上使用 Lima 虚拟机安全部署 OpenClaw:构建你的 AI 隔离沙箱
人工智能·安全·macos·ai智能体·openclaw
❀͜͡傀儡师7 小时前
macOS/Linux Gemini CLI安装指南
linux·运维·macos
liangshanbo12151 天前
[特殊字符] Yazi 终极指南:从安装到精通 (macOS 专属)
macos