Skip to content

fix: stop and remove daemon on netbird CLI formula uninstall - #7

Open
CoderSufiyan wants to merge 1 commit into
netbirdio:mainfrom
CoderSufiyan:fix/issue-5852
Open

fix: stop and remove daemon on netbird CLI formula uninstall#7
CoderSufiyan wants to merge 1 commit into
netbirdio:mainfrom
CoderSufiyan:fix/issue-5852

Conversation

@CoderSufiyan

@CoderSufiyan CoderSufiyan commented Jul 13, 2026

Copy link
Copy Markdown

Problem
brew uninstall netbird leaves behind the running daemon and /Library/LaunchDaemons/netbird.plist because the formula has no cleanup hook.

Solution
Add uninstall_post to bootout the netbird launchd service and remove the plist. Also add caveats reminding users to run netbird service uninstall before upgrading.

Fixes netbirdio/netbird#5852

Validation
ruby -c netbird.rb

Summary by CodeRabbit

  • New Features

    • Automatically stops the NetBird background service and removes its system configuration when uninstalling.
  • Documentation

    • Added guidance for stopping and uninstalling the NetBird service before upgrading or removing the Homebrew package.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Homebrew formula now cleans up the NetBird LaunchDaemon during uninstallation and displays instructions for stopping and uninstalling the service before upgrading or removing the formula.

Changes

NetBird service cleanup

Layer / File(s) Summary
Uninstall cleanup and service guidance
netbird.rb
Adds an uninstall_post hook to stop and remove the LaunchDaemon while suppressing errors, and adds caveats describing required service commands before upgrades or removal.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: mlsmaycon

Poem

A bunny hops past the daemon’s lair,
Boots it out and leaves things bare.
“Stop your service before you upgrade,”
Says the rabbit by the formula gate.
Clean uninstall—now that’s hare-ware!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main uninstall fix for stopping and removing the NetBird daemon.
Linked Issues check ✅ Passed The PR addresses the issue by stopping the launchd daemon and removing the NetBird plist during Homebrew uninstall.
Out of Scope Changes check ✅ Passed The caveats addition is directly related to the uninstall and upgrade behavior and does not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@netbird.rb`:
- Around line 54-59: Replace the unsupported uninstall_post hook with a
supported Homebrew uninstall mechanism so the LaunchDaemon cleanup runs during
brew uninstall. Preserve the existing launchctl bootout and netbird.plist
removal behavior, including ignored errors, and use the formula’s supported
uninstall stanza or lifecycle hook.
- Around line 55-56: Update the uninstall_post cleanup in the netbird formula to
avoid unauthorised system daemon operations during a normal brew uninstall:
either remove the launchctl bootout and plist deletion and rely on the caveat’s
sudo netbird service uninstall, or replace them with an explicitly authorised
uninstall path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ed484d5-9ae0-4f8a-8da8-95bbe40042aa

📥 Commits

Reviewing files that changed from the base of the PR and between 982297a and 94963e3.

📒 Files selected for processing (1)
  • netbird.rb

Comment thread netbird.rb
Comment on lines +54 to +59
def uninstall_post
system "launchctl", "bootout", "system/netbird"
rm_f "/Library/LaunchDaemons/netbird.plist"
rescue
# ignore errors if launchctl is unavailable or service is already stopped
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

brew_repo="$(brew --repository)"
grep -R -nE '\buninstall_post\b' "$brew_repo/Library/Homebrew" || true
grep -R -nE 'def uninstall\b|keg\.uninstall' "$brew_repo/Library/Homebrew" | head -50

Repository: netbirdio/homebrew-tap

Length of output: 202


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the formula file and inspect the relevant section.
wc -l netbird.rb
cat -n netbird.rb | sed -n '1,140p'

Repository: netbirdio/homebrew-tap

Length of output: 3207


🌐 Web query:

Homebrew Formula Cookbook uninstall_post formula hook supported lifecycle uninstall callback

💡 Result:

There is no "uninstall_post" formula hook in the Homebrew Formula lifecycle [1][2]. The term "uninstall_post" often appears in unrelated contexts, such as the CumulusCI tool, which uses it as a task name in its own configuration files [3][4][5]. In the context of Homebrew: 1. Formulae do not support custom Ruby hooks for uninstall actions (e.g., pre_uninstall or post_uninstall) [1][6]. 2. Homebrew's philosophy is that packages should be contained within their prefix (the Cellar) [6]. When a formula is uninstalled, Homebrew removes the files within that specific keg, and generally expects that no state or files are left behind outside the Cellar that would require a custom uninstall hook [6][7]. 3. While Homebrew Casks do support certain lifecycle hooks (such as uninstall_preflight or uninstall_postflight) to handle complex installations or removals, these are distinct from Formulae [8]. If you are encountering references to "uninstall_post" in a project, it is almost certainly a custom task or configuration specific to that application's internal automation, not a native feature of the Homebrew package manager [3][4][9].

Citations:


uninstall_post is not a supported Homebrew formula hook. brew uninstall won’t call this method, so the LaunchDaemon cleanup never runs. Move this to a supported uninstall path or document a separate cleanup step.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@netbird.rb` around lines 54 - 59, Replace the unsupported uninstall_post hook
with a supported Homebrew uninstall mechanism so the LaunchDaemon cleanup runs
during brew uninstall. Preserve the existing launchctl bootout and netbird.plist
removal behavior, including ignored errors, and use the formula’s supported
uninstall stanza or lifecycle hook.

Comment thread netbird.rb
Comment on lines +55 to +56
system "launchctl", "bootout", "system/netbird"
rm_f "/Library/LaunchDaemons/netbird.plist"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== netbird.rb ==\n'
git ls-files | rg '^netbird\.rb$|/netbird\.rb$|^Formula/.*netbird.*\.rb$' || true

for f in $(git ls-files | rg '^netbird\.rb$|/netbird\.rb$|^Formula/.*netbird.*\.rb$' || true); do
  printf '\n--- %s (line-numbered excerpt) ---\n' "$f"
  wc -l "$f"
  sed -n '1,220p' "$f" | cat -n
done

printf '\n== Search for launchctl/launchdaemon references ==\n'
rg -n --hidden --no-ignore-vcs 'launchctl|LaunchDaemons|netbird\.plist|bootout|sudo' .

Repository: netbirdio/homebrew-tap

Length of output: 3869


Use a sudo-capable path for system daemon cleanup. uninstall_post runs as a normal brew uninstall, so launchctl bootout system/netbird and rm_f "/Library/LaunchDaemons/netbird.plist" will usually fail without privileges. Either drop this hook and rely on the caveat’s sudo netbird service uninstall, or run the uninstall under authorization.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@netbird.rb` around lines 55 - 56, Update the uninstall_post cleanup in the
netbird formula to avoid unauthorised system daemon operations during a normal
brew uninstall: either remove the launchctl bootout and plist deletion and rely
on the caveat’s sudo netbird service uninstall, or replace them with an
explicitly authorised uninstall path.

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.

[Bug] homebrew/macOS uninstalling netbird is not full

1 participant