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

Function takeOverActiveLocalServer

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

Source from the content-addressed store, hash-verified

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