History

Fix launchd reinstall after disable

Rhys Sullivan committed 5 months ago

Commit ce495bf1 parent 30ecd422 files · +9 −3Browse files

Unified · Split

2 files
  1. apps/cli/src/service.ts +5 −2
  2. apps/desktop/src/main/service.ts +4 −1
apps/cli/src/service.ts+5−2
@@ -270,8 +270,12 @@ const makeLaunchdBackend = (): ServiceBackend => { · 269 unmodified lines
270270 yield* fs.writeFileString(plistFile, plist, { mode: 0o600 });
271271
272272 // Re-bootstrap cleanly: a stale registration from a prior install would
273− // make `bootstrap` fail with "service already loaded".
273+ // make `bootstrap` fail with "service already loaded". `service
274+ // uninstall` also records the label as disabled in launchd's override
275+ // database; clear that before bootstrapping or a reinstall can fail with
276+ // launchctl's generic "Bootstrap failed: 5" error.
274277 yield* runCommand("launchctl", ["bootout", serviceTarget(uid)]).pipe(Effect.ignore);
278+ yield* runCommand("launchctl", ["enable", serviceTarget(uid)]).pipe(Effect.ignore);
275279 const bootstrap = yield* runCommand("launchctl", ["bootstrap", `gui/${uid}`, plistFile]);
276280 if (bootstrap.code !== 0) {
277281 return yield* Effect.fail(
@@ -280,7 +284,6 @@ const makeLaunchdBackend = (): ServiceBackend => { · 2 unmodified lines
280284 ),
281285 );
282286 }
283− yield* runCommand("launchctl", ["enable", serviceTarget(uid)]).pipe(Effect.ignore);
284287 }),
285288 uninstall: () =>
286289 Effect.gen(function* () {
apps/desktop/src/main/service.ts+4−1
@@ -205,7 +205,11 @@ export const installSupervisedService = async (opts: InstallOptions): Promise<vo · 204 unmodified lines
205205 writeFileSync(plistPath(), plist, { mode: 0o600 });
206206
207207 // Re-bootstrap cleanly so a stale registration doesn't make bootstrap fail.
208+ // `uninstallSupervisedService` also records the label as disabled in
209+ // launchd's override database; clear that before bootstrapping or reinstall
210+ // can fail with launchctl's generic "Bootstrap failed: 5" error.
208211 await runCommand("launchctl", ["bootout", serviceTarget(uid)]);
212+ await runCommand("launchctl", ["enable", serviceTarget(uid)]);
209213 const bootstrap = await runCommand("launchctl", ["bootstrap", `gui/${uid}`, plistPath()]);
210214 if (bootstrap.code !== 0) {
211215 // oxlint-disable-next-line executor/no-error-constructor, executor/no-try-catch-or-throw -- boundary: surfaces to the boot flow
@@ -213,7 +217,6 @@ export const installSupervisedService = async (opts: InstallOptions): Promise<vo · 1 unmodified line
213217 `launchctl bootstrap failed (exit ${bootstrap.code}): ${bootstrap.stderr.trim() || bootstrap.stdout.trim()}`,
214218 );
215219 }
216− await runCommand("launchctl", ["enable", serviceTarget(uid)]);
217220 serviceLog.info(`installed supervised service on port ${opts.port}`);
218221 };
219222

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t