feat: supervise worker with pm2 instead of cron PID-check

Passenger only manages the Next.js app process; the worker now gets
the same crash-recovery/auto-restart via pm2, replacing the cron-driven
PID-file restart hack. Updates README deployment steps accordingly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 14:49:49 +02:00
co-authored by Claude Sonnet 5
parent 65f92abe7b
commit 2b5f68752f
6 changed files with 807 additions and 62 deletions
-36
View File
@@ -1,36 +0,0 @@
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { spawn } from 'child_process'
import path from 'path'
const PID_FILE = path.join(__dirname, 'worker.pid')
function isRunning(pid: number): boolean {
try {
process.kill(pid, 0)
return true
} catch {
return false
}
}
if (existsSync(PID_FILE)) {
const pid = parseInt(readFileSync(PID_FILE, 'utf-8').trim(), 10)
if (!isNaN(pid) && isRunning(pid)) {
console.log(`[cron-check] worker already running (PID ${pid})`)
process.exit(0)
}
}
const child = spawn(
process.execPath,
[require.resolve('tsx/cli'), path.join(__dirname, 'index.ts')],
{ detached: true, stdio: 'ignore' }
)
child.unref()
if (child.pid) {
writeFileSync(PID_FILE, String(child.pid))
console.log(`[cron-check] worker started (PID ${child.pid})`)
}
process.exit(0)