2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/examples/xend-config.sxp
|
2008-08-18 00:24:29 +02:00
|
|
|
===================================================================
|
2010-01-16 01:12:54 +01:00
|
|
|
--- xen-4.0.0-testing.orig/tools/examples/xend-config.sxp
|
|
|
|
+++ xen-4.0.0-testing/tools/examples/xend-config.sxp
|
|
|
|
@@ -304,3 +304,62 @@
|
|
|
|
# we have to realize this may incur security issue and we can't make sure the
|
|
|
|
# device assignment could really work properly even after we do this.
|
|
|
|
#(pci-passthrough-strict-check yes)
|
2008-08-18 00:24:29 +02:00
|
|
|
+
|
2009-05-04 18:38:09 +02:00
|
|
|
+# Domain Locking
|
|
|
|
+# In a multihost environment, domain locking prevents simultaneously
|
|
|
|
+# running a domain on more than one host.
|
|
|
|
+#
|
|
|
|
+# If enabled, xend will execute a external lock utility (defined below)
|
|
|
|
+# on each domain start and stop event. Disabled by default. Set to yes
|
|
|
|
+# to enable domain locking.
|
2008-08-18 00:24:29 +02:00
|
|
|
+#
|
|
|
|
+#(xend-domain-lock no)
|
|
|
|
+
|
|
|
|
+# Path where domain lock is stored if xend-domain-lock is enabled.
|
|
|
|
+# Note: This path must be accessible to all VM Servers participating
|
|
|
|
+# in domain locking, e.g. by specifying a shared mount point.
|
2009-05-04 18:38:09 +02:00
|
|
|
+# Lock is placed in /<xend-domain-lock-path>/<domain-uuid>.
|
2010-04-19 00:21:05 +02:00
|
|
|
+# Default is /var/lib/xend/domains/
|
2008-08-18 00:24:29 +02:00
|
|
|
+#
|
|
|
|
+#(xend-domain-lock-path /var/lib/xend/domains)
|
|
|
|
+
|
2009-05-04 18:38:09 +02:00
|
|
|
+# External locking utility called by xend for acquiring/releasing
|
|
|
|
+# domain lock. By default /etc/xen/scripts/domain-lock will be used
|
|
|
|
+# if xend-domain-lock is set to yes. Set to path of custom locking
|
|
|
|
+# utility to override the default.
|
2008-11-08 20:32:12 +01:00
|
|
|
+#
|
2009-05-04 18:38:09 +02:00
|
|
|
+# Synopsis of lock-util:
|
|
|
|
+# lock-util [-l|-u] -n <vm name> -i <vm uuid> -p <physical host> path"
|
|
|
|
+# -l Acquire (create) lock
|
|
|
|
+# -u Remove lock
|
2008-08-18 00:24:29 +02:00
|
|
|
+# -n vm-name Name of domain
|
|
|
|
+# -i vm-id Id or UUID of domain
|
2009-05-04 18:38:09 +02:00
|
|
|
+# -p phy-host Name of physical host (dom0)
|
|
|
|
+# path /<xend-domain-lock-path>/<vm-uuid>
|
|
|
|
+# Return 0 on success, non-zero on error.
|
|
|
|
+#
|
|
|
|
+# lock-util [-s] path"
|
|
|
|
+# -s Lock status. If lock is acquired, print any contents
|
|
|
|
+# on stdout and return 0. Return non-zero if lock is
|
|
|
|
+# available.
|
|
|
|
+# path /<xend-domain-lock-path>/<vm-uuid>
|
|
|
|
+# If lock is acquired, print any contents on stdout and return 0.
|
|
|
|
+# Return non-zero if lock is available.
|
2008-08-18 00:24:29 +02:00
|
|
|
+#
|
2009-05-04 18:38:09 +02:00
|
|
|
+# Default lock-util behavior:
|
|
|
|
+# On domain start event, domain-lock will create and flock(1)
|
|
|
|
+# /<xend-domain-lock-path>/<vm-uuid>/lock. Every two seconds it
|
|
|
|
+# will write <vm-name>, <vm-id>, <vm-host>, and <tick> to the lock.
|
|
|
|
+# <tick> is running counter.
|
|
|
|
+# On domain stop event, domain-lock will unlock and remove
|
|
|
|
+# /<xend-domain-lock-path>/<vm-uuid>/lock.
|
|
|
|
+#
|
|
|
|
+# Note: If xend-domain-lock-path is a cluster-unaware file system,
|
|
|
|
+# administrator intervention may be required to remove stale
|
|
|
|
+# locks. Consider two hosts using NFS for xend-domain-lock-path
|
|
|
|
+# when HostA, running vm1, crashes. HostB could not acquire a
|
|
|
|
+# lock for vm1 since the NFS server holds an exclusive lock
|
|
|
|
+# acquired by HostA. The lock file must be manually removed
|
|
|
|
+# before starting vm1 on HostA.
|
2008-08-18 00:24:29 +02:00
|
|
|
+#
|
|
|
|
+#(xend-domain-lock-utility domain-lock)
|
2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/python/xen/xend/XendDomainInfo.py
|
2008-08-18 00:24:29 +02:00
|
|
|
===================================================================
|
2010-01-16 01:12:54 +01:00
|
|
|
--- xen-4.0.0-testing.orig/tools/python/xen/xend/XendDomainInfo.py
|
|
|
|
+++ xen-4.0.0-testing/tools/python/xen/xend/XendDomainInfo.py
|
|
|
|
@@ -32,11 +32,12 @@ import re
|
2008-08-18 00:24:29 +02:00
|
|
|
import copy
|
|
|
|
import os
|
2010-01-16 01:12:54 +01:00
|
|
|
import stat
|
2008-08-18 00:24:29 +02:00
|
|
|
+import shutil
|
|
|
|
import traceback
|
|
|
|
from types import StringTypes
|
|
|
|
|
|
|
|
import xen.lowlevel.xc
|
2010-01-16 01:12:54 +01:00
|
|
|
-from xen.util import asserts, auxbin
|
|
|
|
+from xen.util import asserts, auxbin, mkdir
|
2008-08-18 00:24:29 +02:00
|
|
|
from xen.util.blkif import parse_uname
|
|
|
|
import xen.util.xsm.xsm as security
|
|
|
|
from xen.util import xsconstants
|
2010-03-02 01:46:56 +01:00
|
|
|
@@ -466,6 +467,7 @@ class XendDomainInfo:
|
2008-08-18 00:24:29 +02:00
|
|
|
|
|
|
|
if self._stateGet() in (XEN_API_VM_POWER_STATE_HALTED, XEN_API_VM_POWER_STATE_SUSPENDED, XEN_API_VM_POWER_STATE_CRASHED):
|
|
|
|
try:
|
|
|
|
+ self.acquire_running_lock();
|
|
|
|
XendTask.log_progress(0, 30, self._constructDomain)
|
|
|
|
XendTask.log_progress(31, 60, self._initDomain)
|
|
|
|
|
2010-04-03 00:15:37 +02:00
|
|
|
@@ -2979,6 +2981,11 @@ class XendDomainInfo:
|
2008-08-18 00:24:29 +02:00
|
|
|
|
|
|
|
self._stateSet(DOM_STATE_HALTED)
|
|
|
|
self.domid = None # Do not push into _stateSet()!
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ self.release_running_lock()
|
|
|
|
+ except:
|
|
|
|
+ log.exception("Failed to release domain lock.")
|
|
|
|
finally:
|
|
|
|
self.refresh_shutdown_lock.release()
|
|
|
|
|
2010-04-03 00:15:37 +02:00
|
|
|
@@ -4485,6 +4492,74 @@ class XendDomainInfo:
|
2008-08-18 00:24:29 +02:00
|
|
|
def has_device(self, dev_class, dev_uuid):
|
|
|
|
return (dev_uuid in self.info['%s_refs' % dev_class.lower()])
|
|
|
|
|
2009-05-04 18:38:09 +02:00
|
|
|
+ # Return name of host contained in lock file.
|
2008-08-18 00:24:29 +02:00
|
|
|
+ def get_lock_host(self, path):
|
|
|
|
+ fin = os.popen(xoptions.get_xend_domain_lock_utility() + \
|
2008-11-08 20:32:12 +01:00
|
|
|
+ ' -s ' + path, 'r')
|
2008-08-18 00:24:29 +02:00
|
|
|
+ hostname = "unknown"
|
|
|
|
+
|
|
|
|
+ try:
|
2009-05-04 18:38:09 +02:00
|
|
|
+ tokens = fin.readline().split()
|
|
|
|
+ for token in tokens:
|
|
|
|
+ item = token.split('=')
|
|
|
|
+ if item[0] == 'host':
|
|
|
|
+ hostname = item[1]
|
2008-11-08 20:32:12 +01:00
|
|
|
+ return hostname
|
2008-08-18 00:24:29 +02:00
|
|
|
+ finally:
|
|
|
|
+ fin.close()
|
|
|
|
+
|
|
|
|
+ # Acquire a lock for the domain. No-op if domain locking is turned off.
|
|
|
|
+ def acquire_running_lock(self):
|
|
|
|
+ if not xoptions.get_xend_domain_lock():
|
|
|
|
+ return
|
|
|
|
+
|
2009-05-04 18:38:09 +02:00
|
|
|
+ log.debug("Acquiring lock for domain %s" % self.info['name_label'])
|
2008-08-18 00:24:29 +02:00
|
|
|
+ path = xoptions.get_xend_domain_lock_path()
|
|
|
|
+ path = os.path.join(path, self.get_uuid())
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ if not os.path.exists(path):
|
|
|
|
+ mkdir.parents(path, stat.S_IRWXU)
|
|
|
|
+ except:
|
|
|
|
+ log.exception("%s could not be created." % path)
|
|
|
|
+ raise XendError("%s could not be created." % path)
|
|
|
|
+
|
2008-11-08 20:32:12 +01:00
|
|
|
+ status = os.system('%s -l -p %s -n %s -i %s %s' % \
|
2008-08-18 00:24:29 +02:00
|
|
|
+ (xoptions.get_xend_domain_lock_utility(), \
|
2008-11-08 20:32:12 +01:00
|
|
|
+ XendNode.instance().get_name(), \
|
2008-08-18 00:24:29 +02:00
|
|
|
+ self.info['name_label'], \
|
|
|
|
+ self.info['uuid'], \
|
2008-11-08 20:32:12 +01:00
|
|
|
+ path))
|
2008-08-18 00:24:29 +02:00
|
|
|
+ if status != 0:
|
2009-05-04 18:38:09 +02:00
|
|
|
+ log.debug("Failed to aqcuire lock: status = %d" % status)
|
|
|
|
+ raise XendError("The VM is locked and appears to be running on host %s." % self.get_lock_host(path))
|
2008-08-18 00:24:29 +02:00
|
|
|
+
|
2009-05-04 18:38:09 +02:00
|
|
|
+ # Release lock for domain. No-op if domain locking is turned off.
|
|
|
|
+ def release_running_lock(self, name = None):
|
2008-08-18 00:24:29 +02:00
|
|
|
+ if not xoptions.get_xend_domain_lock():
|
|
|
|
+ return
|
|
|
|
+
|
2009-05-04 18:38:09 +02:00
|
|
|
+ dom_name = self.info['name_label']
|
|
|
|
+ if name:
|
|
|
|
+ dom_name = name
|
|
|
|
+ log.debug("Releasing lock for domain %s" % dom_name)
|
|
|
|
+
|
2008-08-18 00:24:29 +02:00
|
|
|
+ path = xoptions.get_xend_domain_lock_path()
|
|
|
|
+ path = os.path.join(path, self.get_uuid())
|
2009-05-04 18:38:09 +02:00
|
|
|
+ status = os.system('%s -u -p %s -n %s -i %s %s' % \
|
2008-08-18 00:24:29 +02:00
|
|
|
+ (xoptions.get_xend_domain_lock_utility(), \
|
2009-05-04 18:38:09 +02:00
|
|
|
+ XendNode.instance().get_name(), \
|
|
|
|
+ dom_name, \
|
|
|
|
+ self.info['uuid'], \
|
2008-08-18 00:24:29 +02:00
|
|
|
+ path))
|
|
|
|
+ if status != 0:
|
2009-05-04 18:38:09 +02:00
|
|
|
+ log.exception("Failed to release lock: status = %s" % status)
|
2008-08-18 00:24:29 +02:00
|
|
|
+ try:
|
|
|
|
+ if len(os.listdir(path)) == 0:
|
|
|
|
+ shutil.rmtree(path)
|
|
|
|
+ except:
|
|
|
|
+ log.exception("Failed to remove unmanaged directory %s." % path)
|
|
|
|
+
|
|
|
|
def __str__(self):
|
|
|
|
return '<domain id=%s name=%s memory=%s state=%s>' % \
|
|
|
|
(str(self.domid), self.info['name_label'],
|
2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/python/xen/xend/XendOptions.py
|
2008-08-18 00:24:29 +02:00
|
|
|
===================================================================
|
2010-01-16 01:12:54 +01:00
|
|
|
--- xen-4.0.0-testing.orig/tools/python/xen/xend/XendOptions.py
|
|
|
|
+++ xen-4.0.0-testing/tools/python/xen/xend/XendOptions.py
|
|
|
|
@@ -154,6 +154,17 @@ class XendOptions:
|
|
|
|
use loose check automatically if necessary."""
|
|
|
|
pci_dev_assign_strict_check_default = True
|
2008-08-18 00:24:29 +02:00
|
|
|
|
|
|
|
+ """Default for the flag indicating whether xend should create
|
|
|
|
+ a lock file for domains when they are started."""
|
|
|
|
+ xend_domain_lock = 'no'
|
|
|
|
+
|
|
|
|
+ """Default domain lock storage path."""
|
2010-04-19 00:21:05 +02:00
|
|
|
+ xend_domain_lock_path_default = '/var/lib/xend/domains'
|
2008-08-18 00:24:29 +02:00
|
|
|
+
|
|
|
|
+ """Default script to acquire/release domain lock"""
|
2010-01-16 01:12:54 +01:00
|
|
|
+ xend_domain_lock_utility = auxbin.scripts_dir() + "/domain-lock"
|
2008-08-18 00:24:29 +02:00
|
|
|
+
|
|
|
|
+
|
|
|
|
def __init__(self):
|
|
|
|
self.configure()
|
|
|
|
|
2010-01-16 01:12:54 +01:00
|
|
|
@@ -398,6 +409,24 @@ class XendOptions:
|
|
|
|
else:
|
|
|
|
return None
|
2008-08-18 00:24:29 +02:00
|
|
|
|
|
|
|
+ def get_xend_domain_lock(self):
|
|
|
|
+ """Get the flag indicating whether xend should create a lock file
|
|
|
|
+ for domains when they are started."""
|
|
|
|
+ return self.get_config_bool("xend-domain-lock", self.xend_domain_lock)
|
|
|
|
+
|
|
|
|
+ def get_xend_domain_lock_path(self):
|
|
|
|
+ """ Get the path for domain lock storage
|
|
|
|
+ """
|
|
|
|
+ return self.get_config_string("xend-domain-lock-path", self.xend_domain_lock_path_default)
|
|
|
|
+
|
|
|
|
+ def get_xend_domain_lock_utility(self):
|
2009-06-12 20:43:24 +02:00
|
|
|
+ s = self.get_config_string('xend-domain-lock-utility')
|
|
|
|
+
|
|
|
|
+ if s:
|
2010-01-16 01:12:54 +01:00
|
|
|
+ return os.path.join(auxbin.scripts_dir(), s)
|
2009-06-12 20:43:24 +02:00
|
|
|
+ else:
|
|
|
|
+ return self.xend_domain_lock_utility
|
2008-08-18 00:24:29 +02:00
|
|
|
+
|
|
|
|
|
2010-01-16 01:12:54 +01:00
|
|
|
def get_vnc_tls(self):
|
|
|
|
return self.get_config_string('vnc-tls', self.xend_vnc_tls)
|
|
|
|
Index: xen-4.0.0-testing/tools/python/xen/xend/XendCheckpoint.py
|
2008-08-18 00:24:29 +02:00
|
|
|
===================================================================
|
2010-01-16 01:12:54 +01:00
|
|
|
--- xen-4.0.0-testing.orig/tools/python/xen/xend/XendCheckpoint.py
|
|
|
|
+++ xen-4.0.0-testing/tools/python/xen/xend/XendCheckpoint.py
|
|
|
|
@@ -131,6 +131,7 @@ def save(fd, dominfo, network, live, dst
|
2009-05-04 18:38:09 +02:00
|
|
|
dominfo.shutdown('suspend')
|
|
|
|
dominfo.waitForSuspend()
|
|
|
|
if line in ('suspend', 'suspended'):
|
|
|
|
+ dominfo.release_running_lock(domain_name)
|
|
|
|
dominfo.migrateDevices(network, dst, DEV_MIGRATE_STEP2,
|
|
|
|
domain_name)
|
|
|
|
log.info("Domain %d suspended.", dominfo.getDomid())
|
2010-01-16 01:12:54 +01:00
|
|
|
@@ -408,6 +409,7 @@ def restore(xd, fd, dominfo = None, paus
|
2009-05-04 18:38:09 +02:00
|
|
|
if not paused:
|
|
|
|
dominfo.unpause()
|
|
|
|
|
|
|
|
+ dominfo.acquire_running_lock()
|
|
|
|
return dominfo
|
2010-03-02 01:46:56 +01:00
|
|
|
except Exception, exn:
|
2009-05-04 18:38:09 +02:00
|
|
|
dominfo.destroy()
|
2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/hotplug/Linux/Makefile
|
2009-05-04 18:38:09 +02:00
|
|
|
===================================================================
|
2010-01-16 01:12:54 +01:00
|
|
|
--- xen-4.0.0-testing.orig/tools/hotplug/Linux/Makefile
|
|
|
|
+++ xen-4.0.0-testing/tools/hotplug/Linux/Makefile
|
|
|
|
@@ -19,6 +19,7 @@ XEN_SCRIPTS += vtpm vtpm-delete
|
2008-08-18 00:24:29 +02:00
|
|
|
XEN_SCRIPTS += xen-hotplug-cleanup
|
|
|
|
XEN_SCRIPTS += external-device-migrate
|
|
|
|
XEN_SCRIPTS += vscsi
|
2009-06-12 20:43:24 +02:00
|
|
|
+XEN_SCRIPTS += domain-lock vm-monitor
|
2008-08-18 00:24:29 +02:00
|
|
|
XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
|
|
|
|
XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
|
|
|
|
XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh
|
2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/hotplug/Linux/domain-lock
|
2009-05-04 18:38:09 +02:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2010-01-16 01:12:54 +01:00
|
|
|
+++ xen-4.0.0-testing/tools/hotplug/Linux/domain-lock
|
2009-05-04 18:38:09 +02:00
|
|
|
@@ -0,0 +1,83 @@
|
|
|
|
+#!/bin/bash
|
|
|
|
+
|
|
|
|
+basedir=$(dirname "$0")
|
|
|
|
+
|
|
|
|
+usage() {
|
|
|
|
+ echo "usage: domain-lock [-l|-u] -n <vm name> -i <vm uuid> -p <physical host> path"
|
|
|
|
+ echo "usage: domain-lock [-s] path"
|
|
|
|
+ echo ""
|
|
|
|
+ echo "-l lock"
|
|
|
|
+ echo "-u unlock"
|
|
|
|
+ echo "-s status (default)"
|
|
|
|
+ echo "-n Virtual Machine name"
|
|
|
|
+ echo "-i Virtual Machine Id or UUID"
|
|
|
|
+ echo "-p Virtual Machine Server (physical host) name"
|
|
|
|
+ echo "path A per-VM, unique location where external lock will be managed"
|
|
|
|
+ exit 1
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+remove_lock(){
|
|
|
|
+ local path=$1/lock
|
|
|
|
+ local name=$2
|
|
|
|
+
|
2009-06-12 20:43:24 +02:00
|
|
|
+ pid=`ps -efwww | grep vm-monitor | grep $name | awk '{print $2}'`
|
2009-05-04 18:38:09 +02:00
|
|
|
+ if [ -n "$pid" ]; then
|
|
|
|
+ kill $pid
|
|
|
|
+ rm -f $path
|
|
|
|
+ fi
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+get_status(){
|
|
|
|
+ local path=$1/lock
|
|
|
|
+ [ -f $path ] || exit 1
|
|
|
|
+
|
|
|
|
+ rc=`flock -xn $path /bin/true`
|
|
|
|
+ cat $path
|
|
|
|
+ exit $rc
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+mode="status"
|
|
|
|
+
|
|
|
|
+while getopts ":lusn:i:p:" opt; do
|
|
|
|
+ case $opt in
|
|
|
|
+ l )
|
|
|
|
+ mode="lock"
|
|
|
|
+ ;;
|
|
|
|
+ u )
|
|
|
|
+ mode="unlock"
|
|
|
|
+ ;;
|
|
|
|
+ s )
|
|
|
|
+ mode="status"
|
|
|
|
+ ;;
|
|
|
|
+ p )
|
|
|
|
+ vm_host=$OPTARG
|
|
|
|
+ ;;
|
|
|
|
+ n )
|
|
|
|
+ vm_name=$OPTARG
|
|
|
|
+ ;;
|
|
|
|
+ i )
|
|
|
|
+ vm_uuid=$OPTARG
|
|
|
|
+ ;;
|
|
|
|
+ \? )
|
|
|
|
+ usage
|
|
|
|
+ ;;
|
|
|
|
+ esac
|
|
|
|
+done
|
|
|
|
+
|
|
|
|
+shift $(($OPTIND - 1))
|
|
|
|
+vm_path=$1
|
|
|
|
+
|
|
|
|
+case $mode in
|
|
|
|
+ lock )
|
|
|
|
+ [ -z "$vm_path" ] || [ -z "$vm_name" ] || [ -z "$vm_uuid" ] || [ -z "$vm_host" ] && usage
|
|
|
|
+ $basedir/set-lock $vm_path $vm_name $vm_uuid $vm_host
|
|
|
|
+ ;;
|
|
|
|
+ unlock )
|
|
|
|
+ [ -z "$vm_path" ] || [ -z "$vm_name" ] || [ -z "$vm_uuid" ] || [ -z "$vm_host" ] && usage
|
|
|
|
+ remove_lock $vm_path $vm_name $vm_uuid $vm_host
|
|
|
|
+ ;;
|
|
|
|
+ status )
|
|
|
|
+ [ -z "$vm_path" ] && usage
|
|
|
|
+ get_status $vm_path
|
|
|
|
+ ;;
|
|
|
|
+esac
|
2010-01-16 01:12:54 +01:00
|
|
|
Index: xen-4.0.0-testing/tools/hotplug/Linux/vm-monitor
|
2009-05-04 18:38:09 +02:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2010-01-16 01:12:54 +01:00
|
|
|
+++ xen-4.0.0-testing/tools/hotplug/Linux/vm-monitor
|
2009-05-04 18:38:09 +02:00
|
|
|
@@ -0,0 +1,41 @@
|
|
|
|
+#!/bin/bash
|
|
|
|
+
|
|
|
|
+basedir=$(dirname "$0")
|
|
|
|
+HA_TICK=2
|
|
|
|
+
|
|
|
|
+monitor() {
|
|
|
|
+ local path=$1
|
|
|
|
+ local name=$2
|
|
|
|
+ local uuid=$3
|
|
|
|
+ local host=$4
|
|
|
|
+ local count=0
|
|
|
|
+ path=$path/lock
|
|
|
|
+
|
|
|
|
+ while :
|
|
|
|
+ do
|
|
|
|
+ echo "name=$name uuid=$uuid host=$host count=$count" > $path
|
|
|
|
+ count=$(($count+1))
|
|
|
|
+ sleep $HA_TICK
|
|
|
|
+ done&
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+create_lock() {
|
|
|
|
+ local path=$1/lock
|
|
|
|
+ local rc=0
|
|
|
|
+
|
|
|
|
+ [ -f $path ] || touch $path
|
2009-06-12 20:43:24 +02:00
|
|
|
+ flock -x -w $HA_TICK $path $basedir/vm-monitor $*
|
2009-05-04 18:38:09 +02:00
|
|
|
+ rc=$?
|
|
|
|
+ if [ $rc -eq 1 ]; then
|
|
|
|
+ echo `cat $path`
|
|
|
|
+ exit 1
|
|
|
|
+ else
|
|
|
|
+ exit $rc
|
|
|
|
+ fi
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+if [ $0 = "$basedir/set-lock" ]; then
|
|
|
|
+ create_lock $*
|
2009-06-12 20:43:24 +02:00
|
|
|
+elif [ $0 = "$basedir/vm-monitor" ]; then
|
2009-05-04 18:38:09 +02:00
|
|
|
+ monitor $*
|
|
|
|
+fi
|