fix(connect): restore launchd running state
This commit is contained in:
2 files changed
+64
-3
No files matched your search
@@ -475,6 +475,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
|
||||
[
|
||||
`npm install --prefix ${runtimeDir} --no-fund --no-audit [email protected]`,
|
||||
"/bin/launchctl print-disabled gui/501",
|
||||
"/bin/launchctl print gui/501/com.t3tools.t3code.server",
|
||||
"/bin/launchctl enable gui/501/com.t3tools.t3code.server",
|
||||
"/bin/launchctl bootout gui/501/com.t3tools.t3code.server",
|
||||
`/bin/launchctl bootstrap gui/501 ${launchAgentPath}`,
|
||||
@@ -574,6 +575,54 @@ it.layer(NodeServices.layer)("BootService", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("leaves a previously stopped macOS LaunchAgent stopped after rollback", () =>
|
||||
Effect.gen(function* () {
|
||||
const { dirs, fs, path } = yield* makeTestContext();
|
||||
const initialService = yield* BootService.make({
|
||||
baseDir: dirs.baseDir,
|
||||
logsDir: dirs.logsDir,
|
||||
cliVersion: "0.0.27",
|
||||
host: makeHost(dirs.stableEntry),
|
||||
}).pipe(Effect.provide(makeRecordingRunnerLayer([])), provideHostRefs(dirs.home, "darwin"));
|
||||
yield* initialService.install;
|
||||
|
||||
const launchAgentPath = path.join(
|
||||
dirs.home,
|
||||
"Library",
|
||||
"LaunchAgents",
|
||||
"com.t3tools.t3code.server.plist",
|
||||
);
|
||||
const previousLaunchAgent = yield* fs.readFileString(launchAgentPath);
|
||||
const commands: Array<RecordedCommand> = [];
|
||||
const repairService = yield* BootService.make({
|
||||
baseDir: dirs.baseDir,
|
||||
logsDir: dirs.logsDir,
|
||||
cliVersion: "0.0.28",
|
||||
host: makeHost(dirs.stableEntry),
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
makeRecordingRunnerLayer(commands, {
|
||||
failWhen: (command, args) =>
|
||||
command === "/bin/launchctl" &&
|
||||
(args.includes("print") || args.includes("bootstrap")),
|
||||
}),
|
||||
),
|
||||
provideHostRefs(dirs.home, "darwin"),
|
||||
);
|
||||
|
||||
const error = yield* repairService.install.pipe(Effect.flip);
|
||||
|
||||
assert.isTrue(isCommandError(error));
|
||||
assert.equal(yield* fs.readFileString(launchAgentPath), previousLaunchAgent);
|
||||
assert.lengthOf(
|
||||
commands.filter(
|
||||
({ command, args }) => command === "/bin/launchctl" && args.includes("bootstrap"),
|
||||
),
|
||||
1,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("stops an orphaned macOS LaunchAgent when its plist is already gone", () =>
|
||||
Effect.gen(function* () {
|
||||
const { dirs } = yield* makeTestContext();
|
||||
|
||||
@@ -550,6 +550,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
|
||||
: Option.none<string>();
|
||||
const previousLaunchAgentDisabled =
|
||||
platform === "darwin" ? yield* readLaunchAgentDisabled() : Option.none<boolean>();
|
||||
const previousLaunchAgentLoaded = platform === "darwin" ? yield* isLaunchAgentLoaded() : false;
|
||||
|
||||
yield* fs.makeDirectory(unitDir, { recursive: true }).pipe(
|
||||
Effect.andThen(
|
||||
@@ -561,7 +562,12 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
|
||||
),
|
||||
Effect.mapError((cause) => new BootServiceInstallError({ cause })),
|
||||
Effect.tapError(() =>
|
||||
rollbackFailedInstall(previousUnit, previousRuntimeLink, previousLaunchAgentDisabled),
|
||||
rollbackFailedInstall(
|
||||
previousUnit,
|
||||
previousRuntimeLink,
|
||||
previousLaunchAgentDisabled,
|
||||
previousLaunchAgentLoaded,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -603,7 +609,12 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
|
||||
yield* runStep("enabling lingering for this user", "loginctl", ["enable-linger"]);
|
||||
}).pipe(
|
||||
Effect.tapError(() =>
|
||||
rollbackFailedInstall(previousUnit, previousRuntimeLink, previousLaunchAgentDisabled),
|
||||
rollbackFailedInstall(
|
||||
previousUnit,
|
||||
previousRuntimeLink,
|
||||
previousLaunchAgentDisabled,
|
||||
previousLaunchAgentLoaded,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -619,6 +630,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
|
||||
previousUnit: Option.Option<string>,
|
||||
previousRuntimeLink: Option.Option<string>,
|
||||
previousLaunchAgentDisabled: Option.Option<boolean>,
|
||||
previousLaunchAgentLoaded: boolean,
|
||||
) {
|
||||
if (platform === "darwin" && launchAgent !== null && userId !== null) {
|
||||
yield* runOptionalStep("/bin/launchctl", ["bootout", launchAgent.serviceTarget]);
|
||||
@@ -631,7 +643,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
|
||||
yield* writeUnit(previousUnit.value).pipe(Effect.ignore);
|
||||
if (Option.getOrElse(previousLaunchAgentDisabled, () => false)) {
|
||||
yield* runOptionalStep("/bin/launchctl", ["disable", launchAgent.serviceTarget]);
|
||||
} else {
|
||||
} else if (previousLaunchAgentLoaded) {
|
||||
yield* runOptionalStep("/bin/launchctl", [
|
||||
"bootstrap",
|
||||
`gui/${String(userId)}`,
|
||||
|
||||
Reference in new issue
Block a user