From aa2579e1abdef65bfe2e2aeb8d2dc3994933b2ca Mon Sep 17 00:00:00 2001 From: Ani Balasubramaniam Date: Tue, 19 May 2026 12:22:23 -0700 Subject: [PATCH] fix: macOS service installer startup issues Fix three issues with the service installer on macOS: 1. Don't use sudo for service stop on macOS. The service is a user LaunchAgent; sudo shifts the home directory to /var/root causing kardianos/service to look for the plist in the wrong location. The stop fails silently, leaving the old service running on the default port, which then forces the port-picker to choose a different port on reinstall. 2. Set RunAtLoad=true in the launchd plist. kardianos/service defaults RunAtLoad to false, so the service wouldn't auto-start after reboot. 3. Only print the listen address after 'service start' when --addr was explicitly provided. Otherwise the output shows the flag default (4242) even though the installed plist may specify a different port. --- cmd/mind-map/service.go | 9 +++++++-- install.sh | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/mind-map/service.go b/cmd/mind-map/service.go index 4694826..ea1f676 100644 --- a/cmd/mind-map/service.go +++ b/cmd/mind-map/service.go @@ -91,6 +91,7 @@ func newServiceConfig(addr, dir, webui string, idleTimeout time.Duration) *servi if runtime.GOOS == "darwin" { cfg.Option = service.KeyValue{ "UserService": true, + "RunAtLoad": true, } } else if runtime.GOOS == "linux" { cfg.UserName = os.Getenv("SUDO_USER") @@ -170,8 +171,12 @@ var serviceStartCmd = &cobra.Command{ return fmt.Errorf("start service: %w", err) } fmt.Println("Service started.") - fmt.Printf(" Web UI: http://%s\n", addr) - fmt.Printf(" MCP endpoint: http://%s/mcp\n", addr) + // Only print the address if explicitly provided; otherwise the plist + // may contain a different addr than the flag default. + if cmd.Flags().Changed("addr") { + fmt.Printf(" Web UI: http://%s\n", addr) + fmt.Printf(" MCP endpoint: http://%s/mcp\n", addr) + } return nil }, } diff --git a/install.sh b/install.sh index bff0e5f..4dbb351 100755 --- a/install.sh +++ b/install.sh @@ -78,8 +78,15 @@ mkdir -p "${HOME}/.mind-map" # Stop existing service before replacing the binary if [ -f "${INSTALL_DIR}/mind-map" ]; then - sudo "${INSTALL_DIR}/mind-map" service stop 2>/dev/null && \ - echo "==> Stopped existing mind-map service" || true + # On macOS the service is a user LaunchAgent; sudo would look for the plist + # under /var/root instead of ~/Library/LaunchAgents, so don't use sudo. + if [[ "$(uname -s)" == "Darwin" ]]; then + "${INSTALL_DIR}/mind-map" service stop 2>/dev/null && \ + echo "==> Stopped existing mind-map service" || true + else + sudo "${INSTALL_DIR}/mind-map" service stop 2>/dev/null && \ + echo "==> Stopped existing mind-map service" || true + fi fi echo "==> Downloading ${TARBALL_NAME}..."