fix: add PID lock to run-fs-scraper-mac.sh — prevent simultaneous instances
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.
This commit is contained in:
parent
681fd5ced6
commit
6be2c131d3
@ -40,7 +40,22 @@ close_tunnel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ── Main ──────────────────────────────────────────────────────────────────────
|
# ── Main ──────────────────────────────────────────────────────────────────────
|
||||||
|
LOCK_FILE="/tmp/tip-fs-scraper.lock"
|
||||||
|
|
||||||
mkdir -p "$(dirname "$LOG")"
|
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 ==="
|
log "=== FS.com Mac Scraper starting ==="
|
||||||
|
|
||||||
# Only close tunnel if we opened it (not if one was already running)
|
# Only close tunnel if we opened it (not if one was already running)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user