MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / takeOverActiveLocalServer

Function takeOverActiveLocalServer

apps/cli/src/main.ts:391–427  ·  view source on GitHub ↗
(input?: {
  readonly onlyKind?: ExecutorLocalServerKind;
})

Source from the content-addressed store, hash-verified

389 });
390
391const takeOverActiveLocalServer = (input?: {
392 readonly onlyKind?: ExecutorLocalServerKind;
393}): Effect.Effect<
394 ExecutorLocalServerManifest | null,
395 Error,
396 FileSystem.FileSystem | PlatformPath.Path
397> =>
398 Effect.gen(function* () {
399 const manifest = yield* readLocalServerManifest();
400 if (!manifest) return null;
401 if (input?.onlyKind && manifest.kind !== input.onlyKind) return null;
402
403 if (!isPidAlive(manifest.pid) || manifest.pid === process.pid) {
404 yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore);
405 return null;
406 }
407
408 yield* terminatePid(manifest.pid).pipe(Effect.ignore);
409 const stopped = yield* waitForUnreachable({
410 check: isServerReachable(manifest.connection.origin),
411 timeoutMs: DAEMON_STOP_TIMEOUT_MS,
412 intervalMs: DAEMON_BOOT_POLL_MS,
413 });
414 if (!stopped) {
415 return yield* Effect.fail(
416 new Error(
417 [
418 `The existing Executor ${manifest.kind} at ${manifest.connection.origin} (pid ${manifest.pid}) did not stop within ${DAEMON_STOP_TIMEOUT_MS / 1000}s.`,
419 "Stop it manually and re-run.",
420 ].join("\n"),
421 ),
422 );
423 }
424
425 yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore);
426 return manifest;
427 });
428
429const publishLocalServerManifest = (input: {
430 readonly kind: ExecutorLocalServerKind;

Callers 3

runDaemonSessionFunction · 0.85
installServiceFunction · 0.85
main.tsFile · 0.85

Calls 6

readLocalServerManifestFunction · 0.90
isPidAliveFunction · 0.90
terminatePidFunction · 0.90
waitForUnreachableFunction · 0.90
isServerReachableFunction · 0.85

Tested by

no test coverage detected