From 546d7ae4a7092c9625804fe53cdea8d12da0dace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Tue, 6 Feb 2024 11:18:35 +0100 Subject: [PATCH] B #6372: Add lock to raft hook script (#2899) * This should fix issues in HA environment, where we sometimes get duplicated virtual IPs (cherry picked from commit 5788a2528eb30bb576950b403c306557d001fd5e) (cherry picked from commit bf628dc9b64f60cde65fbf8032073ec10de76362) --- share/hooks/raft/vip.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/hooks/raft/vip.sh b/share/hooks/raft/vip.sh index ff67669c83..d94844ec52 100755 --- a/share/hooks/raft/vip.sh +++ b/share/hooks/raft/vip.sh @@ -86,9 +86,21 @@ function virtualip() { # main # +if [ -z "${ONE_LOCATION}" ]; then + LOCK_LOCATION=/var/lock/one +else + LOCK_LOCATION=$ONE_LOCATION/var/lock +fi + +LOCK_FILE="$LOCK_LOCATION/vip_sh" + ACTION="$1" shift +# Start of critical section (opens LOCK_FILE with fd 56) +exec 56>$LOCK_FILE +flock -w 60 56 + # Process all parameters in the form of interface:IP while [[ $# -gt 0 ]] do