Modernize macOS uninstaller: fix service management and add force mode
Summary
This PR modernizes the macOS uninstaller to fix critical issues reported in #2347 and implements all recommendations from @natoscott.
Problem
The current uninstall-pcp script has several critical issues:
- Obsolete service management: Uses
/Library/StartupItemswhich hasn't existed on macOS for years - Missing services: Only handled pmcd and pmlogger, ignoring pmie and pmproxy
- Outdated package removal: Used old receipt locations instead of modern
pkgutil - Incomplete cleanup: Left ~80+ directories with "Directory not empty" errors
- Insecure temp files: Used hardcoded
/tmppaths - No force option: No way to do complete cleanup including config/data/logs
Changes
This PR addresses all issues through 4 logical commits:
Commit 1: Fix pmproxy plist typo
- Fixed GNUmakefile where pmproxy was incorrectly installing pmlogger.plist
Commit 2: Modernize service management
- Replace obsolete
/Library/StartupItemswith modernlaunchctlcommands - Support both
bootout(macOS 10.11+) andunloadfor compatibility - Add support for all 4 services: pmcd, pmie, pmlogger, pmproxy
- Use
pkgutil --forgetfor modern package receipt management - Explicitly remove LaunchDaemons plist files
- Preserve config/log files with user notification
Commit 3: Add force mode and mktemp
- Use
mktemp(1)for secure temp directory creation - Add
-f/--forceflag to skip confirmation and perform complete removal - Add
--helpflag for usage information - Implement aggressive cleanup in force mode that removes:
/etc/pcp//var/lib/pcp//var/log/pcp/
Commit 4: Documentation
- Add
HOMEBREW_TAP_UPDATES.mdwith recommendations for aligning Homebrew tap - Add
TESTING_GUIDE.mdwith comprehensive testing procedures - Document force mode usage and testing strategies
Testing
Standard uninstall preserves config/logs:
sudo /usr/local/libexec/pcp/bin/uninstall-pcp
Force mode removes everything:
sudo /usr/local/libexec/pcp/bin/uninstall-pcp --force
See build/mac/TESTING_GUIDE.md for comprehensive testing procedures.
Impact
- Fixes: All service management issues in #2347
- Solves: "Directory not empty" errors with force mode
- Improves: Security with mktemp
- Adds: User choice for config/log preservation
- Maintains: Backward compatibility with fallback launchctl commands
Notes
This PR is marked as DRAFT for manual testing on macOS VMs before final review.
Fixes #2347
@natoscott I think this is good to review and merge if you're ok with it. I've tested manually both force and non-force modes in a UTM VM, they seem to be good. I am going to now aim to integrate any necessary changes into the Homebrew cask repo so that it can uninstall things cleanly there.