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

Function takeOverActiveLocalServer

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

Source from the content-addressed store, hash-verified

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