From 1c5805ab9614dcd4234991fe59b22191d4fd674b Mon Sep 17 00:00:00 2001 From: Rene Fichtmueller Date: Sat, 18 Apr 2026 02:43:28 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20add=20PID=20lock=20to=20run-fs-scraper-m?= =?UTF-8?q?ac.sh=20=E2=80=94=20prevent=20simultaneous=20instances?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds /tmp/tip-fs-scraper.lock PID file to prevent launchd from running a second instance while the previous one is still active (e.g. 2am schedule fires, runs past 10am when launchd fires again). Without this, concurrent instances caused rmSync(storage-fs-phase1) in one instance to delete the Crawlee storage dir while the other was still using it, resulting in ENOENT crashes. --- run-fs-scraper-mac.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/run-fs-scraper-mac.sh b/run-fs-scraper-mac.sh index 92bdd40..3fdab47 100755 --- a/run-fs-scraper-mac.sh +++ b/run-fs-scraper-mac.sh @@ -40,7 +40,22 @@ close_tunnel() { } # ── Main ────────────────────────────────────────────────────────────────────── +LOCK_FILE="/tmp/tip-fs-scraper.lock" + mkdir -p "$(dirname "$LOG")" + +# Prevent simultaneous runs (e.g. launchd fires during a still-running instance) +if [ -f "$LOCK_FILE" ]; then + LOCK_PID=$(cat "$LOCK_FILE" 2>/dev/null || echo "") + if [ -n "$LOCK_PID" ] && kill -0 "$LOCK_PID" 2>/dev/null; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] Already running (PID $LOCK_PID) — skipping" >> "$LOG" + exit 0 + fi + rm -f "$LOCK_FILE" +fi +echo $$ > "$LOCK_FILE" +trap 'rm -f "$LOCK_FILE"' EXIT + log "=== FS.com Mac Scraper starting ===" # Only close tunnel if we opened it (not if one was already running)