Commit 1db0b7cf authored by Luca Bigliardi's avatar Luca Bigliardi Committed by Guido Trotter
Browse files

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: default avatarLuca Bigliardi <shammash@google.com>
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent e7d6946c
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
TARGET_BRIDGE="br0" TARGET_BRIDGE="br0"
DAEMON_PID_FILE="/var/run/dnsmasq.pid" DAEMON_PID_FILE="/var/run/dnsmasq.pid"
LOCKFILE="/var/lock/ganeti_ethers.lock" LOCKFILE="/var/lock/ganeti_ethers.lock"
LOCKTIMEOUT=10
LOCKSLEEP=2
hooks_path=$GANETI_HOOKS_PATH hooks_path=$GANETI_HOOKS_PATH
[ -n "$hooks_path" ] || exit 1 [ -n "$hooks_path" ] || exit 1
...@@ -44,10 +46,17 @@ instance=$GANETI_INSTANCE_NAME ...@@ -44,10 +46,17 @@ instance=$GANETI_INSTANCE_NAME
nic_count=$GANETI_INSTANCE_NIC_COUNT nic_count=$GANETI_INSTANCE_NIC_COUNT
acquire_lockfile() { acquire_lockfile() {
if ! ( set -o noclobber; echo "$$" > $LOCKFILE) 2> /dev/null; then NOW=$(date +%s)
logger -s "Cannot acquire lockfile for ethers update" TIMEOUT=$(($NOW + $LOCKTIMEOUT))
exit 1 while ! ( set -o noclobber; echo "$$" > $LOCKFILE) 2> /dev/null ; do
fi 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 trap "rm -f $LOCKFILE" EXIT
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment