brew services: where to edit configuration?
Asked Answered
N

6

45

Brew services has installed this plist file for mysql.

~ $ brew services list
Name    Status  User      Plist
mysql56 started mh /Users/mh/Library/LaunchAgents/homebrew.mxcl.mysql56.plist

Is this file safe to edit (i.e. will brew ever overwrite changes made here)? Is there another method I should use to modify the file?

Nubbin answered 18/3, 2016 at 16:21 Comment(0)
A
58

All .plist files that come with Formulas can be found in Cellar dir. For instance homebrew.mxcl.mysql.plist is in /usr/local/Cellar/mysql/5.7.14. You can modify it and  brew services will use it.

Alternatively you can modify /Library/LaunchDaemons/homebrew.mxcl.mysql.plist and make it immutable with sudo chflags uchg /Library/LaunchDaemons/homebrew.mxcl.mysql.plist. This won't allow brew to rewrite or modify .plist file.

Allerus answered 2/8, 2016 at 11:10 Comment(6)
Your are not going to be able to start the brew services again by making the .plist immutable. When starting I get: Error: Operation not permitted @ unlink_internal - /Users/ci/Library/LaunchAgents/homebrew.mxcl.gitlab-runner.plist. Brew services requires the plist file to be writable.Motta
I just tried this out by putting different values on the LaunchDaemons plist file, and I can confirm that the correct file to edit is the Cellar version. The LaunchDaemons version will get copied to / overwritten by the Cellar version on a brew services start.Buttonball
As an additional note, it's easier to go to /usr/local/opt/ instead of /usr/local/Cellar because /opt just symlinks to the appropriate match in /Cellar. This guide explains how brew services interact with LaunchAgents: robots.thoughtbot.com/…Buttonball
For quickly, find the .plist file by running command: locate homebrew.mxcl.mysql56.plist the file path will be displayed in output.Chafe
After this commit, you should use brew edit <service> to update the plist method in the formula. The plist file is generated every time you restart a service.Stonecutter
Jenkins will not start if you make the file unmodifiable. I found my origin at /opt/homebrew with Ventura ARM. How I hate macOS.Synesthesia
R
15
  1. Copy /Users/mh/Library/LaunchAgents/homebrew.mxcl.mysql56.plist somewhere
  2. make changes to copy of plist
  3. run brew services start mysql56 {path to modified copy of plist file}

Update 2022 - for newer versions:

  1. run brew services start mysql56 --file=path to modified copy of plist file
Rutland answered 25/10, 2017 at 17:28 Comment(1)
With newer version, note that file as last argument is deprecated! Use --file= to specify a plist file instead.Byebye
D
8

Short answer:

Edit the configuration in usr/local/Cellar/ + name of the Formula / + .plist file

NOT in the file listed next to the daemon in brew services listing


Long answer:

When you install a Formula, its plist file lands in usr/local/Cellar, in a dir named after the formula.

When you spawn a daemon with brew services start, this file is then copied to the running user's Library/LaunchAgents/, e.g.:

for root, it's Library/LaunchAgents/

for a normal user - ~/Library/LaunchAgents

This is important, there is no point in changing this file, it's just a copy that will be overwritten next time you run the service as this user.

However, you can examine this file to see what configuration was used for this particular instance of the service.

Daggna answered 23/2, 2020 at 8:10 Comment(0)
H
6

I (unfortunately) don't know which file you can edit, but I can confirm that editing anything in the Library/LaunchAgents directory will be overwritten by brew services on the next start, so editing it directly isn't going to help.

Harakiri answered 3/7, 2016 at 3:43 Comment(3)
Confirmed. And this is a pain in the ass.Zennie
However you can stop that from happening by using chflags uchg <file> (and later chflags nouchg <file>).Coelenterate
You are able to edit both, but you should edit the Cellar version of the file. @Harakiri answer is correct, brew services start overwrites the LaunchAgents version of the file with whatever was in Cellar .Buttonball
S
1

When you install a package with Homebrew formula a .plist file is placed in the package folder (usually /usr/local/Cellar/... folder).

In OSX this file is copyed/deleted to/from the

/Library/LaunchDaemons/

folder every time tou start/stop the service with Homebrew:

brew services start <the-app>
brew services stop  <the-app>

Better than 'blocking' this file is acting over the file in your package folder...

This example is for OSX/Mojave & MariaDB:

Suppose you want to change the default data folder and the TCP port from 3306 to 3308.

Edit the:

/usr/local/Cellar/mariadb/10.4.6_1/homebrew.mxcl.mariadb.plist

Locate this section in the XML and make you desired changes (choose you desired folder):

...
<string>/usr/local/opt/mariadb/bin/mysqld_safe</string>
<string>--datadir=/DAT/mariadb</string>     
<string>--port=3308</string> 
...

Then just stop and restart the service with Homebrew, et voilá. You can use netstat to confirm:

netstat | grep 3308 
Soluk answered 17/10, 2019 at 22:38 Comment(0)
C
1

I got the same issue in year 2024. Now the paths are bit different, and the behavior is different too.

You can find the config file with command: brew services list yet, brew services start will generate / overwrite the config file. The original template file path somehow changes over time. Right now for my case it is: /opt/homebrew/opt/...

Conway answered 8/2 at 23:0 Comment(1)
run brew --prefix mysql . Which will give you the directory. Then edit homebrew.mxcl.mysql.plist in that directory. Then restart the servicePortis

© 2022 - 2024 — McMap. All rights reserved.