pcp icon indicating copy to clipboard operation
pcp copied to clipboard

Modernize macOS uninstaller: fix service management and add force mode

Open tallpsmith opened this issue 1 month ago • 1 comments

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:

  1. Obsolete service management: Uses /Library/StartupItems which hasn't existed on macOS for years
  2. Missing services: Only handled pmcd and pmlogger, ignoring pmie and pmproxy
  3. Outdated package removal: Used old receipt locations instead of modern pkgutil
  4. Incomplete cleanup: Left ~80+ directories with "Directory not empty" errors
  5. Insecure temp files: Used hardcoded /tmp paths
  6. 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/StartupItems with modern launchctl commands
  • Support both bootout (macOS 10.11+) and unload for compatibility
  • Add support for all 4 services: pmcd, pmie, pmlogger, pmproxy
  • Use pkgutil --forget for 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/--force flag to skip confirmation and perform complete removal
  • Add --help flag 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.md with recommendations for aligning Homebrew tap
  • Add TESTING_GUIDE.md with 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

tallpsmith avatar Dec 05 '25 01:12 tallpsmith

@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.

tallpsmith avatar Dec 05 '25 05:12 tallpsmith