feat(server): run the background service on macOS via launchd #6286
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/6286/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/cloud/bootService.ts line 317Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -85,0 +276,21 @@276+ ],277+ activate: [278+ // A persisted `launchctl disable` override refuses bootstrap; clear it.279+ {280+ step: "enabling the launch agent",281+ command: "launchctl",282+ args: ["enable", serviceTarget],283+ optional: true,284+ },285+ {286+ step: "loading the launch agent",287+ command: "launchctl",288+ args: ["bootstrap", domainTarget, unitPath],289+ optional: true,290+ },291+ // Start last. No administrative state write occurs after this succeeds.292+ {293+ step: "starting the service",294+ command: "launchctl",295+ args: ["kickstart", "-k", serviceTarget],296+ },
- apps/server/src/cloud/bootService.ts line 144Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -85,0 +124,21 @@124+ ` <array>`,125+ ` <string>${escapeXmlText(plan.nodePath)}</string>`,126+ ` <string>${escapeXmlText(plan.launcherPath)}</string>`,127+ ` </array>`,128+ ` <key>EnvironmentVariables</key>`,129+ ` <dict>`,130+ ` <key>T3CODE_HOME</key>`,131+ ` <string>${escapeXmlText(plan.baseDir)}</string>`,132+ ` <key>${BOOT_SERVICE_UNIT_ENV}</key>`,133+ ` <string>${BOOT_SERVICE_PLIST_FILE}</string>`,134+ ` </dict>`,135+ ` <key>WorkingDirectory</key>`,136+ ` <string>${escapeXmlText(options.homeDir)}</string>`,137+ ` <key>RunAtLoad</key>`,138+ ` <true/>`,139+ ` <key>KeepAlive</key>`,140+ ` <true/>`,141+ ` <key>ThrottleInterval</key>`,142+ ` <integer>5</integer>`,143+ ` <key>ExitTimeOut</key>`,144+ ` <integer>90</integer>`,
- docs/user/background-service.md lines 52 to 52OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -37,3 +35,18 @@37-launcher snapshots the database before a remote candidate starts, so database updates roll back38-with the server version. An older launcher may require one local `service update` before this is39-available.35+The service runs a small stable launcher. Exact T3 Code versions are installed separately, so a36+failed remote candidate can return to the previous version without rewriting the service37+definition. The launcher snapshots the database before a remote candidate starts, so database38+updates roll back with the server version. An older launcher may require one local39+`service update` before this is available.40+41+## Platform Support42+43+**Linux** uses a systemd user unit at `~/.config/systemd/user/t3code.service`. The service starts44+when the machine boots and keeps running after you log out (lingering is enabled during install).45+46+**macOS** uses a launch agent at `~/Library/LaunchAgents/com.t3tools.t3code.service.plist`. It47+starts when you log in, not when the Mac boots, and it stops when you log out; macOS has no48+equivalent of Linux lingering for user agents. For a Mac that should stay reachable unattended,49+turn on automatic login (System Settings → Users & Groups; unavailable while FileVault is on) and50+keep the Mac from sleeping.51+52+Two more macOS notes:
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
- @@ -85,0 +279,21 @@279+ const serviceTarget = `${domainTarget}/${BOOT_SERVICE_LAUNCHD_LABEL}`;280+ // bootout/enable are optional: they fail on not-loaded states that are fine281+ // to proceed from. The strict `bootstrap` runs last and is also the start:282+ // loading a RunAtLoad/KeepAlive plist starts the job, so a separate283+ // kickstart would kill and restart a server it just booted. A lingering job284+ // that survived bootout, or a gui domain with nobody logged in at the285+ // screen (SSH install), makes bootstrap fail the flow loudly rather than286+ // silently keeping a stale server.287+ return {288+ kind: "launchd",289+ unitPath,290+ render: (plan) => renderBootServicePlist(plan, { homeDir: input.homeDir }),291+ // Without --wait, bootout returns in milliseconds while the job drains292+ // for up to ExitTimeOut, and a bootstrap during the drain fails EIO.293+ // --wait (present on modern macOS, absent from the man page) blocks until294+ // the job is removed from the domain; STOP_STEP_TIMEOUT outlives it.295+ stop: [296+ {297+ step: "stopping the installed launch agent",298+ command: "launchctl",299+ args: ["bootout", "--wait", serviceTarget],
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
3cdab0e2-46d3-4cd5-817a-95c4e2704be1You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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