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
相关推荐
朝阳5812 小时前
Mac 上找窗口,可以先按这几种情况来
macos
william_yangshun4 小时前
DigUp 实测:用多模态嵌入做 macOS 全盘语义搜索
macos·向量检索
czt_java5 小时前
网络基础入门:IPv4、IPv6、私网公网、MAC、以太网帧与 DNS 学习笔记
网络·学习·macos
HEJOO95 小时前
iOS 高效绘图:从 Core Graphics 到 Metal 的实践指南
macos·ios·cocoa
Hello_Pyhx5 小时前
RetainPDF v4.2.6:Windows、macOS、Linux PDF 翻译的 API 配置与任务排查
linux·macos·pdf
Rebecca.Yan6 小时前
Claude Code 深度学习
macos
hey you~6 小时前
嘈杂环境ASR识别优化:降噪、VAD切分与Whisper模型微调完整教程(2026版)
macos·whisper·xcode
Khalil三省9 小时前
Mac怎么显示桌面歌词?Apple Music和Spotify也能开
macos·开源·效率工具·音乐
sakiko_11 小时前
纯Appdelegate控制的老项目适配Xcode27(iOS27SDK)
macos·objective-c·cocoa
2501_915921431 天前
详细教程:使用Perfdog工具测量iOS应用的功耗性能与优化方法
android·macos·ios·小程序·uni-app·cocoa·iphone