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:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user