MCPcopy
hub / github.com/inkeep/open-knowledge / readProcessLock

Function readProcessLock

packages/server/src/process-lock.ts:225–252  ·  view source on GitHub ↗
(opts: {
  lockName: LockName;
  lockDir: string;
})

Source from the content-addressed store, hash-verified

223}
224
225export function readProcessLock(opts: {
226 lockName: LockName;
227 lockDir: string;
228}): ProcessLockMetadata | null {
229 const { lockName, lockDir } = opts;
230 const lockPath = lockFilePath(lockDir, lockName);
231 if (!existsSync(lockPath)) return null;
232
233 let existing: ProcessLockMetadata;
234 try {
235 const parsed = JSON.parse(readFileSync(lockPath, 'utf-8'));
236 if (!parsed || typeof parsed !== 'object' || !isValidLockPid((parsed as { pid?: unknown }).pid))
237 return null;
238 existing = parsed as ProcessLockMetadata;
239 } catch {
240 return null;
241 }
242
243 if (existing.hostname !== hostname()) return null;
244 if (!isProcessAlive(existing.pid)) {
245 try {
246 unlinkSync(lockPath);
247 } catch {}
248 return null;
249 }
250
251 return existing;
252}
253
254export type ReadProcessLockResult =
255 | { status: 'absent' }

Callers 4

readServerLockFunction · 0.90
readUiLockFunction · 0.90

Calls 4

isValidLockPidFunction · 0.90
isProcessAliveFunction · 0.90
lockFilePathFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected