← back to All Designerwallcoverings
use owner-safe PM2 CLI wrapper
c9e5e8ee7e439e4120745c6f3518a5342c09583b · 2026-08-30 20:54:49 -0700 · Steve Abrams
Files touched
M scripts/crawl-microsites.js
Diff
commit c9e5e8ee7e439e4120745c6f3518a5342c09583b
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Sun Aug 30 20:54:49 2026 -0700
use owner-safe PM2 CLI wrapper
---
scripts/crawl-microsites.js | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/scripts/crawl-microsites.js b/scripts/crawl-microsites.js
index c228953..8c2cb81 100644
--- a/scripts/crawl-microsites.js
+++ b/scripts/crawl-microsites.js
@@ -76,25 +76,8 @@ function seedVendorPairsFromUnified() {
function seedFromPm2() {
try {
const cp = require('child_process');
- // Serialize this `pm2 jlist` against the fleet's other pm2-CLI callers (keep-alive 60s)
- // via the shared atomic mkdir lock on ~/.pm2/cli.lock.d (TK-10970). Concurrent pm2 CLI
- // access races on rpc.sock and auto-forks orphan "God" daemons (the pm2-fracture class,
- // TK-10932). FAIL-OPEN: proceeds anyway if the lock can't be acquired in budget (status
- // quo) — never blocks the crawl. mkdir is atomic; a stale lock (>20s) is stolen.
- const nodefs = require('fs'), nodepath = require('path');
- const PM2_LOCK = nodepath.join(process.env.PM2_HOME || nodepath.join(process.env.HOME, '.pm2'), 'cli.lock.d');
- const withPm2Lock = (fn) => {
- const sleep = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
- // deadline (10s) > STALE_MS (8s) so a dead holder's lock is reclaimed within one wait;
- // STALE_MS >> real <1s pm2-CLI hold so a live holder is never stolen (Kimi review).
- const deadline = Date.now() + 10000; let held = false;
- while (Date.now() < deadline) {
- try { nodefs.mkdirSync(PM2_LOCK); held = true; break; }
- catch (e) { if (e.code !== 'EEXIST') break; try { if (Date.now() - nodefs.statSync(PM2_LOCK).mtimeMs > 8000) { nodefs.rmdirSync(PM2_LOCK); continue; } } catch {} sleep(80); }
- }
- try { return fn(); } finally { if (held) { try { nodefs.rmdirSync(PM2_LOCK); } catch {} } }
- };
- const procs = JSON.parse(withPm2Lock(() => cp.execSync('pm2 jlist', { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })));
+ const serialized = '/Users/macstudio3/.claude/skills/keep-alive/proposals/TK-10970/pm2-serialized.js';
+ const procs = JSON.parse(cp.execFileSync(process.execPath, [serialized, 'jlist'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }));
const lsof = cp.execSync('lsof -nP -iTCP -sTCP:LISTEN 2>/dev/null || true', { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
const pidPort = new Map();
for (const line of lsof.split('\n')) {
← 43684c2 crawl-microsites: coherent pm2-lock constants (deadline 10s
·
back to All Designerwallcoverings
·
add creds-in-URL fetch guard to gated pages (TK-10984) 2d035d0 →