Skip to content

fix(setup): use LaunchDaemon on macOS so agent starts at boot without login#923

Open
corfehill-cmd wants to merge 1 commit into
JKHeadley:mainfrom
corfehill-cmd:fix/launch-daemon-boot-without-login
Open

fix(setup): use LaunchDaemon on macOS so agent starts at boot without login#923
corfehill-cmd wants to merge 1 commit into
JKHeadley:mainfrom
corfehill-cmd:fix/launch-daemon-boot-without-login

Conversation

@corfehill-cmd

Copy link
Copy Markdown

Problem

On macOS, instar installs a LaunchAgent plist into ~/Library/LaunchAgents/. LaunchAgents are only loaded after a user logs in at the GUI — so on a home server or always-on Mac, the agent stays dead after a system reboot until someone physically logs in at the console.

Solution

Switch to a LaunchDaemon (/Library/LaunchDaemons/) with the UserName key set to the installing user. LaunchDaemons are loaded by launchd at system boot, before any GUI session, so the agent starts automatically after a reboot.

Changes

  • Rename installMacOSLaunchAgentinstallMacOSLaunchDaemon
  • Write plist to /Library/LaunchDaemons/ via sudo cp + chown root:wheel + chmod 644
  • Add UserName and GroupName keys so the process runs as the correct user
  • Add HOME env var (LaunchDaemons do not inherit the user environment)
  • Use sudo launchctl bootstrap system to load at system scope
  • Update uninstallAutoStart to bootout/remove the daemon plist (with sudo)
  • Migration path: if a legacy ~/Library/LaunchAgents/ plist exists it is automatically unloaded and removed during install so the agent doesn't start twice on login

Notes

The setup wizard runs interactively so the sudo prompt is visible to the user. The launchctlLoadAllowed() gate (used for test hygiene) is preserved.

The fleet watchdog (installFleetWatchdog) is left as a LaunchAgent for now since it is a periodic check script with StartInterval, not the main boot concern — that can be a follow-up.

…t login

LaunchAgents (~/Library/LaunchAgents/) only run after a user logs in at
the console. For a home server or always-on deployment, this means the
agent stays dead after a reboot until someone physically logs in.

Switch to a LaunchDaemon (/Library/LaunchDaemons/) with the UserName key
set to the installing user. LaunchDaemons are loaded by launchd at system
boot, before any GUI login, so the agent comes up automatically.

Changes:
- Rename installMacOSLaunchAgent → installMacOSLaunchDaemon
- Write plist to /Library/LaunchDaemons/ (via sudo cp + chown/chmod)
- Add UserName and GroupName keys so the process runs as the user
- Add HOME env var (LaunchDaemons don't inherit user environment)
- Use `sudo launchctl bootstrap system` to load at system scope
- Update uninstallAutoStart to boot-out/remove the daemon (+ cleanup any
  legacy LaunchAgent plist for existing installs)
- Migration path: if a legacy ~/Library/LaunchAgents plist exists it is
  unloaded and removed during install to avoid double-start on login
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

@adrianco is attempting to deploy a commit to the sagemind Team on Vercel.

A member of the Team first needs to authorize it.

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.

2 participants