← back to Wallco Ai
add mkdir-based mutex wrapper for cron ticks (macOS has no flock)
1d8b4c6553356869edea587b107e14d3a44d5956 · 2026-05-26 07:41:09 -0700 · Steve Abrams
Files touched
Diff
commit 1d8b4c6553356869edea587b107e14d3a44d5956
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue May 26 07:41:09 2026 -0700
add mkdir-based mutex wrapper for cron ticks (macOS has no flock)
---
scripts/with-lock.sh | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/scripts/with-lock.sh b/scripts/with-lock.sh
new file mode 100755
index 0000000..50aaea5
--- /dev/null
+++ b/scripts/with-lock.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+# Mutex wrapper for cron commands. If another instance holds the lock, exit 0 silently
+# (cron retries on next interval). Detects + recovers stale locks from killed processes.
+#
+# Usage: with-lock.sh <lock-name> <command> [args...]
+#
+# Concretely for wallco-ai: generator_tick + drunk_animals_tick share lock-name "wallco-gen"
+# so only one heavy generation tick runs at a time. macOS has no flock(1).
+
+set -u
+LOCK_NAME="${1:?lock-name required}"
+shift
+LOCK_DIR="/tmp/wallco-ai-${LOCK_NAME}.lock"
+PID_FILE="${LOCK_DIR}/pid"
+
+acquire() {
+ if mkdir "$LOCK_DIR" 2>/dev/null; then
+ echo $$ > "$PID_FILE"
+ return 0
+ fi
+ if [ -f "$PID_FILE" ]; then
+ local OLD_PID
+ OLD_PID=$(cat "$PID_FILE" 2>/dev/null)
+ if [ -n "$OLD_PID" ] && ! kill -0 "$OLD_PID" 2>/dev/null; then
+ rm -rf "$LOCK_DIR"
+ if mkdir "$LOCK_DIR" 2>/dev/null; then
+ echo $$ > "$PID_FILE"
+ return 0
+ fi
+ fi
+ fi
+ return 1
+}
+
+if ! acquire; then
+ exit 0
+fi
+
+trap 'rm -rf "$LOCK_DIR"' EXIT INT TERM
+
+"$@"
← a2dd3ee ComfyUI default → Mac1 (192.168.1.133:8188), Mac2 was OOM-ki
·
back to Wallco Ai
·
edges-agent: unpublish 11,274 seam-defect designs + admin re 57869a4 →