History

fix supervised and local regressions

Rhys Sullivan committed 5 months ago

Commit 831bfbd1 parent 498e4a614 files · +997 −52Browse files

Showing the changes to apps/cli/src (3 of 14 files). Show all

Unified · Split

3 files
  1. apps/cli/src/daemon.ts +2 −2
  2. apps/cli/src/main.ts +2 −2
  3. apps/cli/src/service.ts +18 −5
apps/cli/src/daemon.ts+2−2
@@ -89,8 +89,8 @@ export const isExecutorServerReachable = ( · 88 unmodified lines
8989 // misconfigured base URL can't leak the bearer token to a third-party host.
9090 const url = new URL("/api/health", input.baseUrl);
9191 const response = await fetch(url, { signal: AbortSignal.timeout(2000) });
92− await response.body?.cancel();
93− return response.ok;
92+ const body = await response.text();
93+ return response.ok && body.trim() === "ok";
9494 }).pipe(Effect.catchCause(() => Effect.succeed(false)));
9595
9696 // ---------------------------------------------------------------------------
apps/cli/src/main.ts+2−2
@@ -2270,8 +2270,8 @@ const openInBrowser = (url: string): Effect.Effect<void> => · 2269 unmodified lines
22702270 */
22712271 const openCommand = Command.make("open", {}, () =>
22722272 Effect.gen(function* () {
2273− const manifest = yield* readLocalServerManifest();
2274− if (!manifest || !isPidAlive(manifest.pid)) {
2273+ const manifest = yield* readActiveLocalServerManifest().pipe(Effect.orElseSucceed(() => null));
2274+ if (!manifest) {
22752275 console.log("No local Executor server is running.");
22762276 console.log(`Start one with: ${cliPrefix} web`);
22772277 return;
apps/cli/src/service.ts+18−5
@@ -340,11 +340,24 @@ export interface SystemdUnitOptions { · 339 unmodified lines
340340 readonly stderrPath: string;
341341 }
342342
343+const SYSTEMD_BARE_VALUE = /^[A-Za-z0-9_@%+=:,./-]+$/;
344+
345+const systemdQuote = (value: string): string => {
346+ if (SYSTEMD_BARE_VALUE.test(value)) return value;
347+ const escaped = value
348+ .replaceAll("\\", "\\\\")
349+ .replaceAll('"', '\\"')
350+ .replaceAll("\n", "\\n")
351+ .replaceAll("\r", "\\r")
352+ .replaceAll("\t", "\\t");
353+ return `"${escaped}"`;
354+};
355+
343356 /** Render a systemd --user unit. Pure (snapshot-tested). */
344357 export const generateSystemdUnit = (options: SystemdUnitOptions): string => {
345− const execStart = options.execStart.map((arg) => (/\s/.test(arg) ? `"${arg}"` : arg)).join(" ");
358+ const execStart = options.execStart.map(systemdQuote).join(" ");
346359 const env = Object.entries(options.environment)
347− .map(([key, value]) => `Environment=${key}=${value}`)
360+ .map(([key, value]) => `Environment=${systemdQuote(`${key}=${value}`)}`)
348361 .join("\n");
349362 return `[Unit]
350363 Description=Executor supervised daemon
@@ -354,9 +367,9 @@ After=default.target · 3 unmodified lines
354367 Type=simple
355368 ExecStart=${execStart}
356369 ${env}
357−WorkingDirectory=${options.workingDirectory}
358−StandardOutput=append:${options.stdoutPath}
359−StandardError=append:${options.stderrPath}
370+WorkingDirectory=${systemdQuote(options.workingDirectory)}
371+StandardOutput=${systemdQuote(`append:${options.stdoutPath}`)}
372+StandardError=${systemdQuote(`append:${options.stderrPath}`)}
360373 Restart=on-failure
361374 RestartSec=5s
362375

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t