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

Allow systemctl stop on keep_alive services - Restart=on-failure #17639

Open
1 task done
lethedata opened this issue Jul 6, 2024 · 5 comments
Open
1 task done

Allow systemctl stop on keep_alive services - Restart=on-failure #17639

lethedata opened this issue Jul 6, 2024 · 5 comments
Labels
features New features help wanted We want help addressing this

Comments

@lethedata
Copy link

Verification

Provide a detailed description of the proposed feature

When brew generates a systemd unit file with keep_alive true in the formula, it generates with Restart=always which prevents manually killing the service with systemctl directly. By switching to Restart=on-failure Linux users will be able to kill services with systemctl while still retaining a proper keep-alive functionality1. This would also limit the need for brew to handle generating multiple exit codes (I think it was done this way due to a limitation on the MacOS side).

I think this change only requires a single line be changed in the service.rb file but I'm not familiar enough the code to be sure.

options << "Restart=always" if @keep_alive.present? && @keep_alive[:always].present?

What is the motivation for the feature?

Being unable to kill a service with systemctl as a workaround to the brew services kill keep-alive limitation. The service only needed to be temporarily killed, not completely disabled, and being unable to manually kill it seemed a bit odd.

How will the feature be relevant to at least 90% of Homebrew users?

It will allow Linux users manually kill services with systemctl stop --user homebrew.SERVICENAME.service without needing to fully disable the service.

What alternatives to the feature have been considered?

I wasn't able to find any previous discussion but but an alternative would be to have brew handle multiple exit states within the keep-alive but I think this would diverge the Linux and MacOS side requiring quite a bit of change.

Footnotes

  1. systemd.service manual

@lethedata lethedata added the features New features label Jul 6, 2024
@MikeMcQuaid
Copy link
Member

I don't think we should change the default behaviour at this point but I can see an argument for having a different DSL to accomplish what you'd want.

CC @SMillerDev for thoughts.

@SMillerDev
Copy link
Member

SMillerDev commented Jul 8, 2024

IIRC there is a different keepalive parameter for this, where it only keeps the service alive on failures.

I'm also not that excited about optimising something in brew service so that you can manage them outside of brew, since that's not really a goal for brew service in my opinion.

@lethedata
Copy link
Author

lethedata commented Jul 8, 2024

IIRC there is a different keepalive parameter for this, where it only keeps the service alive on failures.

Well now I'm a bit confused. I went back and looked and found reference to different states under the Formula Cookbook but it looks like other states aren't implemented on a systemd generation? I'm like 99% sure I'm missing something here. I'll try testing it when I have sometime later today.

Keep alive only if the job crashed:

I'm also not that excited about optimising something in brew service so that you can manage them outside of brew, since that's not really a goal for brew service in my opinion.

I can agree with that. Figured I'd ask as I struggled to think of a use case where always restart makes since on desktop and now that you mention it I can see wanting to avoid management drift.

@SMillerDev
Copy link
Member

Well now I'm a bit confused. I went back and looked and found reference to different states under the Formula Cookbook but it looks like other states aren't implemented on a systemd generation? I'm like 99% sure I'm missing something here. I'll try testing it when I have sometime later today.

It is possible that I never implemented all options for systemd.

@MikeMcQuaid
Copy link
Member

@lethedata Thanks for the link! In that case: yes, this should definitely be implemented.

@MikeMcQuaid MikeMcQuaid added the help wanted We want help addressing this label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
features New features help wanted We want help addressing this
Projects
None yet
Development

No branches or pull requests

3 participants