mirror of
https://github.com/getpaseo/paseo.git
synced 2026-08-14 20:32:46 +00:00
fix: move PID lock to bootstrap.ts for all entrypoints
This commit is contained in:
@@ -59,6 +59,7 @@ import type {
|
|||||||
AgentClient,
|
AgentClient,
|
||||||
AgentProvider,
|
AgentProvider,
|
||||||
} from "./agent/agent-sdk-types.js";
|
} from "./agent/agent-sdk-types.js";
|
||||||
|
import { acquirePidLock, releasePidLock } from "./pid-lock.js";
|
||||||
|
|
||||||
type AgentMcpTransportMap = Map<string, StreamableHTTPServerTransport>;
|
type AgentMcpTransportMap = Map<string, StreamableHTTPServerTransport>;
|
||||||
|
|
||||||
@@ -498,6 +499,9 @@ export async function createPaseoDaemon(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
|
// Acquire PID lock
|
||||||
|
await acquirePidLock(config.paseoHome, selfIdMcpSocketPath);
|
||||||
|
|
||||||
// Start Self-ID MCP socket server first
|
// Start Self-ID MCP socket server first
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const onError = (err: Error) => {
|
const onError = (err: Error) => {
|
||||||
@@ -604,6 +608,8 @@ export async function createPaseoDaemon(
|
|||||||
if (existsSync(selfIdMcpSocketPath)) {
|
if (existsSync(selfIdMcpSocketPath)) {
|
||||||
unlinkSync(selfIdMcpSocketPath);
|
unlinkSync(selfIdMcpSocketPath);
|
||||||
}
|
}
|
||||||
|
// Release PID lock
|
||||||
|
await releasePidLock(config.paseoHome);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { loadConfig } from "./config.js";
|
|||||||
import { resolvePaseoHome } from "./paseo-home.js";
|
import { resolvePaseoHome } from "./paseo-home.js";
|
||||||
import { createRootLogger } from "./logger.js";
|
import { createRootLogger } from "./logger.js";
|
||||||
import { loadPersistedConfig } from "./persisted-config.js";
|
import { loadPersistedConfig } from "./persisted-config.js";
|
||||||
|
import { PidLockError } from "./pid-lock.js";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const paseoHome = resolvePaseoHome();
|
const paseoHome = resolvePaseoHome();
|
||||||
@@ -21,7 +22,15 @@ async function main() {
|
|||||||
}
|
}
|
||||||
const daemon = await createPaseoDaemon(config, logger);
|
const daemon = await createPaseoDaemon(config, logger);
|
||||||
|
|
||||||
|
try {
|
||||||
await daemon.start();
|
await daemon.start();
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof PidLockError) {
|
||||||
|
logger.error({ pid: err.existingLock?.pid }, err.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
let shuttingDown = false;
|
let shuttingDown = false;
|
||||||
const handleShutdown = async (signal: string) => {
|
const handleShutdown = async (signal: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user