From 1db0b7cf51b9613a4253cd10927ce11dc391c805 Mon Sep 17 00:00:00 2001 From: Luca Bigliardi Date: Wed, 5 Aug 2009 18:48:20 +0100 Subject: [PATCH] ethers hook: reduce the probability of data loss The hook was exiting immediately if lock was not acquired, entering a timed loop to have more chances when acquiring the lock. Signed-off-by: Luca Bigliardi Signed-off-by: Guido Trotter Reviewed-by: Guido Trotter --- doc/examples/hooks/ethers | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/examples/hooks/ethers b/doc/examples/hooks/ethers index 35a66b0..4de44fd 100755 --- a/doc/examples/hooks/ethers +++ b/doc/examples/hooks/ethers @@ -36,6 +36,8 @@ TARGET_BRIDGE="br0" DAEMON_PID_FILE="/var/run/dnsmasq.pid" LOCKFILE="/var/lock/ganeti_ethers.lock" +LOCKTIMEOUT=10 +LOCKSLEEP=2 hooks_path=$GANETI_HOOKS_PATH [ -n "$hooks_path" ] || exit 1 @@ -44,10 +46,17 @@ instance=$GANETI_INSTANCE_NAME nic_count=$GANETI_INSTANCE_NIC_COUNT acquire_lockfile() { - if ! ( set -o noclobber; echo "$$" > $LOCKFILE) 2> /dev/null; then - logger -s "Cannot acquire lockfile for ethers update" - exit 1 - fi + NOW=$(date +%s) + TIMEOUT=$(($NOW + $LOCKTIMEOUT)) + while ! ( set -o noclobber; echo "$$" > $LOCKFILE) 2> /dev/null ; do + NOW=$(date +%s) + if [ $NOW -ge $TIMEOUT ]; then + echo "Cannot acquire lockfile for ethers update, giving up" + exit 1 + fi + echo "Cannot acquire lockfile for ethers update, waiting" + sleep $LOCKSLEEP + done trap "rm -f $LOCKFILE" EXIT } -- 1.7.10.4