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

Function takeOverActiveLocalServer

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

Source from the content-addressed store, hash-verified

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