×

编辑 brew services 正确的plist启动文件

2022-07-04 13:39:24 Falcon

再一次领教 Homebrew 是多么诡异的,反直觉的。

比如说使用列出服务

brew services list

Name              Status    User   File
beanstalkd        started   falcon ~/Library/LaunchAgents/homebrew.mxcl.beanstalkd.plist
memcached         none
mongodb-community none
mysql             started   falcon ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
openresty         started   falcon ~/Library/LaunchAgents/homebrew.mxcl.openresty.plist
php@8.0           started   falcon ~/Library/LaunchAgents/homebrew.mxcl.php@8.0.plist
...

这时候你会很自然地想,如果要编辑服务的启动的配置,比如php@8.0应该是编辑后面列出的文件路径:~/Library/LaunchAgents/homebrew.mxcl.php@8.0.plist ,然而并非如此。

当你编辑完之后,执行:

brew services restart php@8.0

你会发现刚才编辑的 homebrew.mxcl.php@8.0.plist 被还原回了未编辑前的内容。WTF?

正确的方法是编辑:

/usr/local/Cellar/你的应用[/版本号]/homebrew.mxcl.应用.plist

比如上面的 php@8.0 的plist路径就是

/usr/local/Cellar/php@8.0/8.0.20/homebrew.mxcl.php@8.0.plist

执行 brew start/restart 服务后会将此文件复制到 ~/Library/LaunchAgents/

这就是直接编辑 brew services list 下的配置文件后会被覆盖后的原因。尽管如此我依然很想说一句: fuck you homebrew!

What's more:

还有一种方法,据说在新版homebrew可用,就是在运行brew service后面追加配置文件的位置,如:

brew services start php@8.0 【plist文件的路径】

 

本文收录于