Skip to content

services: recognize both Linux service labels - #23792

Merged
MikeMcQuaid merged 1 commit into
mainfrom
services-compatible-linux-labels
Sep 5, 2026
Merged

services: recognize both Linux service labels#23792
MikeMcQuaid merged 1 commit into
mainfrom
services-compatible-linux-labels

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

brew services assumes a Linux service is always named homebrew.<formula>. This is phase one of moving that default to sh.brew.<formula>, mirroring #23741 for macOS: discovery and control now accept either systemd unit name, so both forms can coexist safely before the default is flipped. The unit name written to disk does not change here.

Formulae using the default Linux name expose both names. An explicit name linux: stays single valued even when it matches a default, and now serializes explicitly so it survives the later default change; a Formula subclass overriding service_name keeps its custom identity. Status probes every compatible unit and reports the one holding the PID; stop and kill act on the exact units found, including a running service whose timer is inactive; start and run will not register a second unit when the alternate name is already loaded; orphan cleanup stays pinned to the unit it discovered. brew bundle version pinned lookup and the Utils::Service probes accept either unit filename.

Unit files are only removed after systemctl disable, so replacing or unregistering the alternate name cannot leave a dangling .wants symlink. Timers are regenerated from the formula, and a package-provided timer only has its Unit= rewritten when it names a compatible label. An accepted --no-wait stop still cleans up. Status probes are cached per wrapper and invalidated after every mutation. macOS and launchd behavior is unchanged.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Code (Fable 5.1) drafted the implementation and tests; I reviewed the diff, verified the new tests fail without the change and pass with it, and ran brew lgtm --online.


Copilot AI balanced review requested due to automatic review settings September 5, 2026 00:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Moderate issues can leave running services behind or dangling systemd symlinks.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds support for both legacy and canonical Linux systemd service labels across discovery, lifecycle management, and Bundle lookup.

Changes:

  • Exposes compatible systemd labels and paths.
  • Updates service/timer discovery, status, lifecycle, and cleanup.
  • Adds tests for aliases, timers, probes, and Bundle lookup.

Required fixes:

  • services/cli.rb: Do not remove a unit file when systemctl disable fails (moderate).
  • services/cli.rb: Always include a running service label when stopping or killing timed formulae, even if another timer is active (moderate).
  • services/formula_wrapper.rb: Probe service units as well as timers for every compatible label (moderate).
File summaries
File Description
Library/Homebrew/utils/service.rb Probes compatible systemd units.
Library/Homebrew/test/utils/service_spec.rb Tests compatible service probes.
Library/Homebrew/test/services/formula_wrapper_spec.rb Tests wrapper discovery and timers.
Library/Homebrew/test/services/cli_spec.rb Tests lifecycle and cleanup behavior.
Library/Homebrew/test/formula_spec.rb Tests service names and systemd paths.
Library/Homebrew/test/bundle/brew_services_spec.rb Tests compatible Bundle lookup.
Library/Homebrew/services/formula_wrapper.rb Discovers, caches, and probes compatible units.
Library/Homebrew/services/cli.rb Controls and removes compatible units.
Library/Homebrew/service.rb Defines compatible Linux service labels.
Library/Homebrew/formula.rb Exposes compatible systemd paths.
Library/Homebrew/bundle/brew_services.rb Finds compatible versioned service files.
Review details

Suppressed comments (1)

Library/Homebrew/services/cli.rb:350

  • This fallback has the same mixed-timer gap as stop: for timed services, a non-empty loaded_service_names may identify an active compatible timer while active_service_name identifies a different compatible unit holding the PID. In that state kill stops only the timer's service label and leaves the actual process running. Include the active label as well.
            killed_service_names = service.loaded_service_names.presence || [service.active_service_name]
  • Files reviewed: 11/11 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread Library/Homebrew/services/cli.rb
Comment thread Library/Homebrew/services/cli.rb
Comment thread Library/Homebrew/services/formula_wrapper.rb
@p-linnane
p-linnane force-pushed the services-compatible-linux-labels branch from 6bb94af to d147207 Compare September 5, 2026 00:28
Signed-off-by: Patrick Linnane <patrick@linnane.io>
@p-linnane
p-linnane force-pushed the services-compatible-linux-labels branch from d147207 to 8c83898 Compare September 5, 2026 00:40

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks again!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 5, 2026
Merged via the queue into main with commit f4e4e46 Sep 5, 2026
53 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the services-compatible-linux-labels branch September 5, 2026 06:56
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