Revision e24999ab doc/examples/hooks/ethers

b/doc/examples/hooks/ethers
35 35
# bridge to /etc/ethers.
36 36
TARGET_BRIDGE="br0"
37 37
DAEMON_PID_FILE="/var/run/dnsmasq.pid"
38

  
39
# In order to handle concurrent execution of this lock, we use the $LOCKFILE.
40
# LOCKFILE_CREATE and LOCKFILE_REMOVE are the path names for the lockfile-progs
41
# programs which we use as helpers.
38 42
LOCKFILE="/var/lock/ganeti_ethers.lock"
39
LOCKTIMEOUT=10
40
LOCKSLEEP=2
43
LOCKFILE_CREATE="/usr/bin/lockfile-create"
44
LOCKFILE_REMOVE="/usr/bin/lockfile-remove"
41 45

  
42 46
hooks_path=$GANETI_HOOKS_PATH
43 47
[ -n "$hooks_path" ] || exit 1
......
46 50
nic_count=$GANETI_INSTANCE_NIC_COUNT
47 51

  
48 52
acquire_lockfile() {
49
  NOW=$(date +%s)
50
  TIMEOUT=$(($NOW + $LOCKTIMEOUT))
51
  while ! ( set -o noclobber; echo "$$" > $LOCKFILE) 2> /dev/null ; do
52
    NOW=$(date +%s)
53
    if [ $NOW -ge $TIMEOUT ]; then
54
      logger -s "Cannot acquire lockfile for ethers update, giving up"
55
      exit 1
56
    fi
57
    logger -s "Cannot acquire lockfile for ethers update, waiting"
58
    sleep $LOCKSLEEP
59
  done
60
  trap "rm -f $LOCKFILE" EXIT
53
  $LOCKFILE_CREATE -l $LOCKFILE || exit 1
54
  trap "$LOCKFILE_REMOVE -l $LOCKFILE" EXIT
61 55
}
62 56

  
63 57
update_ethers_from_new() {

Also available in: Unified diff