×

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

Falcon 2022-07-04 views:
摘要

正在生成中……

再一次领教 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文件的路径】

update20240517

旧版homebrew intel cpu的php@8.0的配置文件位于:  /usr/local/Cellar/php@8.0/8.0.20/homebrew.mxcl.php@8.0.plist

为了在同一台机器上运行多个版本的php-fpm, 我修改了部分内容,加了指定配置文件,也就是 --fpm-config 的启动参数,这里备份一下。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.php@8.0</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/php@8.0/sbin/php-fpm</string>
        <string>--nodaemonize</string>
        <string>--fpm-config</string>
        <string>/usr/local/etc/php/8.0/php-fpm.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/php-fpm80.log</string>
    <key>WorkingDirectory</key>
    <string>/usr/local/var</string>
</dict>
</plist>

新版的homebrew会将启动的plist文件放在 /opt/homebrew/Cellar/下,比如php8.2

/opt/homebrew/Cellar/php/8.2.5/homebrew.mxcl.php.plist 

而日志的路径也变了

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>homebrew.mxcl.php</string>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>Background</string>
		<string>LoginWindow</string>
		<string>StandardIO</string>
		<string>System</string>
	</array>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/homebrew/opt/php/sbin/php-fpm</string>
		<string>--nodaemonize</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/opt/homebrew/var/log/php-fpm.log</string>
	<key>WorkingDirectory</key>
	<string>/opt/homebrew/var</string>
</dict>
</plist>

修改后,如果以后更新php8.2,比如更新到8.2.6 ,需要修改php-fpm文件的位置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>homebrew.mxcl.php@8.2</string>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>Background</string>
		<string>LoginWindow</string>
		<string>StandardIO</string>
		<string>System</string>
	</array>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/homebrew/Cellar/php/8.2.5/sbin/php-fpm</string>
		<string>--nodaemonize</string>
    <string>--fpm-config</string>
    <string>/opt/homebrew/etc/php/8.2/php-fpm.conf</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/opt/homebrew/var/log/php-fpm82.log</string>
	<key>WorkingDirectory</key>
	<string>/opt/homebrew/var</string>
</dict>
</plist>

 现在我这台  m1 芯片的mac,混合了新版和旧版homebrew的软件,好混乱,要找个时机重新安装了。

本文收录于