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
相关推荐
皮卡车厘子1 天前
Mac 挂载目录
macos
良逍Ai出海1 天前
在 Windows & macOS 上安装 Claude Code,并使用第三方 Key 的完整教程
windows·macos
热爱生活的五柒1 天前
linux/mac/wsl如何使用claude code,并配置免费的硅基流动API?(官方的需要付费订阅)
linux·运维·macos
胖胖大王叫我来巡山1 天前
mac本地安装DataEase桌面版
macos
奋斗者1号1 天前
OpenClaw 部署方式对比:云端、WSL、Mac 本机、Ubuntu 虚拟机(2026年2月最新主流实践)
linux·ubuntu·macos
玉梅小洋1 天前
Android SDK 安装指南(MacOS 和 Windows)
android·windows·macos·sdk
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
胖胖大王叫我来巡山1 天前
Mac通过源码安装部署SQLBOT
macos
June bug2 天前
【领域知识】广告全链路测试
macos·objective-c·cocoa
作孽就得先起床2 天前
Xcode设置中文
macos