* Read the lockfile and validate it. * Returns null if the lockfile doesn't exist or is stale (dead PID).
()
| 84 | * Returns null if the lockfile doesn't exist or is stale (dead PID). |
| 85 | */ |
| 86 | async read(): Promise<ServerLockData | null> { |
| 87 | try { |
| 88 | await fs.access(this.lockPath); |
| 89 | const content = await fs.readFile(this.lockPath, "utf-8"); |
| 90 | const data = ServerLockDataSchema.parse(JSON.parse(content)); |
| 91 | |
| 92 | // Validate PID is still alive |
| 93 | if (!this.isProcessAlive(data.pid)) { |
| 94 | // Clean up stale lockfile |
| 95 | await this.release(); |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | return data; |
| 100 | } catch { |
| 101 | return null; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Release the lockfile by deleting it. |