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

Function stopDaemon

apps/cli/src/main.ts:881–951  ·  view source on GitHub ↗
(
  baseUrl: string,
)

Source from the content-addressed store, hash-verified

879 }).pipe(Effect.mapError(toError));
880
881const stopDaemon = (
882 baseUrl: string,
883): Effect.Effect<void, Error, FileSystem.FileSystem | PlatformPath.Path> =>
884 Effect.gen(function* () {
885 const target = yield* resolveDaemonTarget(baseUrl);
886 const host = canonicalDaemonHost(target.hostname);
887 const scopeId = target.scopeId;
888 const record = yield* readDaemonRecord({ hostname: host, port: target.port });
889 const reachable = yield* isServerReachable(target.baseUrl);
890
891 if (!record) {
892 if (reachable) {
893 return yield* Effect.fail(
894 new Error(
895 [
896 `Executor is reachable at ${target.baseUrl} but no daemon record exists.`,
897 "It may not be managed by this CLI process.",
898 "Stop it from the terminal/session where it was started.",
899 ].join("\n"),
900 ),
901 );
902 }
903 console.log(`No daemon running at ${target.baseUrl}.`);
904 return;
905 }
906
907 if (!isPidAlive(record.pid)) {
908 yield* removeDaemonRecord({ hostname: host, port: target.port });
909 yield* removeDaemonPointer({ hostname: host, scopeId }).pipe(Effect.ignore);
910 if (reachable) {
911 return yield* Effect.fail(
912 new Error(
913 [
914 `Daemon record for ${target.baseUrl} points to dead pid ${record.pid}, but endpoint is still reachable.`,
915 "Refusing to stop an unknown process without ownership metadata.",
916 ].join("\n"),
917 ),
918 );
919 }
920 console.log(
921 `No daemon running at ${target.baseUrl} (removed stale record for pid ${record.pid}).`,
922 );
923 return;
924 }
925
926 console.log(`Stopping daemon at ${target.baseUrl} (pid ${record.pid})...`);
927
928 yield* terminatePid(record.pid);
929
930 const stopped = yield* waitForUnreachable({
931 check: isServerReachable(target.baseUrl),
932 timeoutMs: DAEMON_STOP_TIMEOUT_MS,
933 intervalMs: DAEMON_BOOT_POLL_MS,
934 });
935
936 if (!stopped) {
937 return yield* Effect.fail(
938 new Error(

Callers 1

main.tsFile · 0.70

Calls 11

canonicalDaemonHostFunction · 0.90
readDaemonRecordFunction · 0.90
isPidAliveFunction · 0.90
removeDaemonRecordFunction · 0.90
removeDaemonPointerFunction · 0.90
terminatePidFunction · 0.90
waitForUnreachableFunction · 0.90
resolveDaemonTargetFunction · 0.85
isServerReachableFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected