fix(replicas): do not flock on manual repair-data

Operator --repair was blocked when pm2 watch owned /tmp lock file.
Only --repair-if-needed uses flock; lock path moved under deploy/.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 12:39:45 +03:30
co-authored by Cursor
parent 16d562caa5
commit 693b1ef93e
2 changed files with 14 additions and 6 deletions
+1
View File
@@ -12,6 +12,7 @@ coverage
# replica DSNs contain live DB passwords # replica DSNs contain live DB passwords
deploy/replicas.env deploy/replicas.env
deploy/.replica-data.lock
# SMS import target files may contain live DB passwords # SMS import target files may contain live DB passwords
prisma/khanegi-sms-targets.json prisma/khanegi-sms-targets.json
+10 -3
View File
@@ -208,13 +208,20 @@ check_replicas() {
return "$needs_repair" return "$needs_repair"
} }
LOCK_FILE="${REPLICA_DATA_LOCK:-/tmp/superadmin-replica-data.lock}" LOCK_FILE="${REPLICA_DATA_LOCK:-$API_DIR/deploy/.replica-data.lock}"
if [[ "$MODE" != "--check" ]] && command -v flock >/dev/null; then # --repair is operator-initiated; never block on flock (avoids /tmp permission fights with pm2 user).
exec 9>"$LOCK_FILE" if [[ "$MODE" == "--repair-if-needed" ]] && command -v flock >/dev/null; then
mkdir -p "$(dirname "$LOCK_FILE")"
touch "$LOCK_FILE" 2>/dev/null || true
chmod 666 "$LOCK_FILE" 2>/dev/null || true
if exec 9>>"$LOCK_FILE" 2>/dev/null; then
if ! flock -n 9; then if ! flock -n 9; then
echo "replica data sync already running — skip" echo "replica data sync already running — skip"
exit 0 exit 0
fi fi
else
echo " ! lock unavailable ($LOCK_FILE) — continuing without flock" >&2
fi
fi fi
if [[ "$MODE" == "--check" ]]; then if [[ "$MODE" == "--check" ]]; then