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
相关推荐
goodmao9 小时前
【macOS】【mouse】设置鼠标大小
macos·计算机外设·鼠标·mouse
Magnum Lehar10 小时前
macos信息采集器appledataharvester-3
macos·网络安全·系统安全
川川菜鸟12 小时前
Claude Code 安装与配置完整指南(Mac)
macos
WarmSword13 小时前
mac上用cursor/vscode调试root权限进程
c++·ide·vscode·macos·mac
Magnum Lehar14 小时前
macos的信息采集器appledataHarvester-2
macos·网络安全·系统安全
echo-niuben15 小时前
macOS 端已如何正常安装并配置XcodeBuildMCP ?
macos
刘某某.15 小时前
Mac上缺失宋体字体,只有宋体-简
macos
Tom·Ge16 小时前
在macOS上安装OpenClaw并实现Chrome网站自动化测试
chrome·macos·策略模式
Lo-Y-eH17 小时前
Mac 安装 Ollama 部署 DeepSeek 模型
macos·ollama·deepseek·cherry studio
仙剑魔尊重楼1 天前
iMazing 3.1.3官方中文版新功能介绍
macos·objective-c·cocoa