Keep daemon logs after a button restart

This commit is contained in:
Fisto
2026-09-17 08:42:09 +02:00
parent d886d22d89
commit 445c6ca2fb
3 changed files with 18 additions and 2 deletions
+7 -2
View File
@@ -10,6 +10,7 @@
*/
import { spawn } from "node:child_process";
import { closeSync, openSync } from "node:fs";
import { config as loadEnv } from "dotenv";
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -1051,14 +1052,18 @@ function restartDaemon(): void {
const args = [...process.execArgv, ...process.argv.slice(1)];
const command = `${quote(process.execPath)} ${args.map(quote).join(" ")}`;
console.log("[daemon] restart requested: spawning a replacement");
const logPath = process.env.VESKSLOP_DAEMON_LOG ?? join(dirname(tokenFile), "daemon.log");
console.log(`[daemon] restart requested: spawning a replacement, appending to ${logPath}`);
const logFd = openSync(logPath, "a");
const child = spawn("sh", ["-c", `sleep 2; exec ${command}`], {
detached: true,
stdio: "ignore",
stdio: ["ignore", logFd, logFd],
cwd: process.cwd(),
env: { ...process.env, VESKSLOP_DAEMON_RESTART: "1" }
});
child.unref();
closeSync(logFd);
setTimeout(() => shutdown(true), 300);
}