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

Function planServiceInstall

apps/cli/src/daemon.ts:319–360  ·  view source on GitHub ↗
(input: {
  readonly registered: boolean;
  readonly running: boolean;
  readonly activeKind: "cli-daemon" | "desktop-sidecar" | "foreground" | null;
  readonly activePid?: number | null;
  readonly servicePid?: number | null;
  readonly activeVersion: string | null;
  readonly activeExecutablePath?: string | null;
  readonly activePort: number | null;
  readonly requestedPort: number;
  readonly currentVersion: string;
  readonly currentExecutablePath?: string | null;
})

Source from the content-addressed store, hash-verified

317export type ServiceInstallPlan = "noop" | "reinstall" | "takeover-then-install";
318
319export const planServiceInstall = (input: {
320 readonly registered: boolean;
321 readonly running: boolean;
322 readonly activeKind: "cli-daemon" | "desktop-sidecar" | "foreground" | null;
323 readonly activePid?: number | null;
324 readonly servicePid?: number | null;
325 readonly activeVersion: string | null;
326 readonly activeExecutablePath?: string | null;
327 readonly activePort: number | null;
328 readonly requestedPort: number;
329 readonly currentVersion: string;
330 readonly currentExecutablePath?: string | null;
331}): ServiceInstallPlan => {
332 if (input.activeKind !== null && input.activeKind !== "cli-daemon") {
333 return "takeover-then-install";
334 }
335
336 if (input.registered && input.running) {
337 if (
338 input.activeKind === "cli-daemon" &&
339 input.activePid !== undefined &&
340 input.activePid !== null &&
341 input.servicePid !== undefined &&
342 input.servicePid !== null &&
343 input.activePid !== input.servicePid
344 ) {
345 return "takeover-then-install";
346 }
347
348 const executableMatches =
349 !input.activeExecutablePath ||
350 !input.currentExecutablePath ||
351 input.activeExecutablePath === input.currentExecutablePath;
352 return input.activeVersion === input.currentVersion &&
353 input.activePort === input.requestedPort &&
354 executableMatches
355 ? "noop"
356 : "reinstall";
357 }
358
359 return "takeover-then-install";
360};

Callers 2

daemon.test.tsFile · 0.90
installServiceFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected