Skip to content

Commit

Permalink
fix(agent): handle long socket file path
Browse files Browse the repository at this point in the history
fix(agent): handle long socket file path

fix(agent): handle long socket file path
  • Loading branch information
tsirysndr committed Jul 27, 2024
1 parent 6fb47d3 commit 86cfc2b
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createId } from "../deps.ts";
import { dir, brightGreen, wait, green, procfile } from "../deps.ts";

export async function isLogged(): Promise<boolean> {
Expand Down Expand Up @@ -478,6 +479,18 @@ export async function stopServices(cwd: string) {
const services = [];
// deno-lint-ignore no-explicit-any
let infos: Record<string, any> = {};
const id = createId();

if (cwd.length > 64) {
const ln = new Deno.Command("bash", {
args: ["-c", `ln -s ${cwd} $HOME/${id}`],
stdout: "inherit",
stderr: "inherit",
}).spawn();
await ln.status;
}

const home = Deno.env.get("HOME")!;

for (const file of files) {
const manifest = procfile.parse(Deno.readTextFileSync(cwd + "/" + file));
Expand All @@ -491,15 +504,27 @@ export async function stopServices(cwd: string) {
const socket = file.replace("Procfile", ".overmind.sock");

try {
await writeToSocket(cwd + "/" + socket, "stop\n");
await writeToSocket(
(cwd.length > 64 ? `${home}/${id}` : cwd) + "/" + socket,
"stop\n"
);
} catch (e) {
console.log(`Failed to stop ${green(service)}`);
console.log(e);
console.log(cwd, socket);
console.log((cwd.length > 64 ? `${home}/${id}` : cwd) + "/" + socket);
continue;
}

console.log(`Successfully stopped ${green(service)}`);
}
}

if (cwd.length > 64) {
const rm = new Deno.Command("bash", {
args: ["-c", `rm $HOME/${id}`],
stdout: "inherit",
stderr: "inherit",
}).spawn();
await rm.status;
}
}

0 comments on commit 86cfc2b

Please sign in to comment.