Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brew bundle services helper #19552

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add brew bundle services helper #19552

wants to merge 1 commit into from

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Mar 20, 2025

A nice shortcut to quickly start and stop all formulae with services in your Brewfile. This makes it nicer if you have e.g. differing database versions (which often still share the same port) between projects.

@Bo98 Bo98 force-pushed the bundle-services branch from 4b126ef to a4a04de Compare March 20, 2025 07:41
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good so far! What happens if there's an existing service already running, will this automatically stop it? If not: that seems desirable.


# We parse from a command invocation so that brew wrappers can invoke special actions
# for the elevated nature of `brew services`
output = Utils.safe_popen_read(HOMEBREW_BREW_FILE, "services", "info", "--json", formula.full_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does brew services list --json contain the information we need? If so, would be nice to use that instead. If not, maybe it'd be nice to add that information in there.

Copy link
Member Author

@Bo98 Bo98 Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list is a small subset of info. I use 4 fields from the JSON, 3 of which are not in list.

Could maybe add them though we'd be near the point of making it not a subset anymore.

I think maybe a better option is to allow info to take in multiple arguments: #19565

@@ -53,6 +53,7 @@ def self.output(hash, verbose:)
return out unless verbose

out += "File: #{hash[:file]} #{pretty_bool(hash[:file].present?)}\n"
out += "Registered at login: #{pretty_bool(hash[:registered])}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could/should this be in list instead/as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't really need to be.

The information is technically already there in list - if it's in LaunchAgents then it's registered. It's just not very good to consume as a JSON API.

Technically doesn't need to be in info non-JSON either but it's in the verbose section which is probably a right fit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking of the benefits for list are that you can get this information for all formulae in a single call.

@Bo98
Copy link
Member Author

Bo98 commented Mar 21, 2025

What happens if there's an existing service already running, will this automatically stop it?

Not currently. brew services does not support temporarily stopping a service well at the moment (there's kill but the service can just auto-restart). I want to avoid removing the LaunchAgents service.

Not sure how such CLI should look. brew services stop --keep?

@Bo98 Bo98 force-pushed the bundle-services branch from a4a04de to d300326 Compare March 21, 2025 04:06
@Bo98 Bo98 force-pushed the bundle-services branch from d300326 to 486ec7d Compare March 21, 2025 07:24
@MikeMcQuaid
Copy link
Member

Not currently. brew services does not support temporarily stopping a service well at the moment (there's kill but the service can just auto-restart). I want to avoid removing the LaunchAgents service.

Not sure how such CLI should look. brew services stop --keep?

Don't feel strongly about the API. I agree with not removing the service if possible but, if it's not, it feels more sensible to remove it.

I think for run to be useful in this context, it needs to be able to also stop. If one project is running postgresql@14 and another postgresql@15 on the same ports, you need to be able to provide a way to ensure that brew bundle services can not only start postgresql@15 but also stop postgresql@14 if needed. We already have some context for this with the conflicts_with: ["mysql"] brew bundle DSL; this feels like another good use of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants