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
相关推荐
pop_xiaoli15 小时前
【iOS】dyld加载
macos·ios·objective-c·cocoa
程序员小崔日记19 小时前
当 AIR 只支持 Mac,我开始重新思考操作系统这件事
macos·操作系统·ai编程
一个人旅程~1 天前
黑苹果系统都支持哪些硬件键盘和笔记本型号,以老旧电脑dell n4020为例安装黑苹果的可能性分析
经验分享·macos·电脑
Eloudy1 天前
macOS 上开启 SSH 服务
运维·macos·ssh
蜜汁小强1 天前
macOS 开发者的 tmux 实战配置:分屏导航、vi 复制模式与系统剪贴板一站打通
macos·策略模式
SaN-V2 天前
MacOS 下 VS Code 中 Codex 通过 SSH 连接远程服务器无法使用的问题排查与解决
服务器·macos·chatgpt·ssh·codex
一只小白菜2 天前
[特殊字符] 解决 Mac M5 芯片上 Ollama 运行报错:升级 macOS Tahoe 26.4.1 后恢复正常
macos
爱吃香蕉的阿豪3 天前
Mac 远程操作 Windows 开发:ZeroTier + JetBrains 实战指南
windows·macos·zerotoer
大嘴皮猴儿4 天前
从零开始学商品图翻译:小白也能快速掌握的多语言文字处理与上架技巧
大数据·ide·人工智能·macos·新媒体运营·xcode·自动翻译
空中海4 天前
第六章:iOS导航与路由系统
macos·ios·cocoa