summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-07-10 14:43:23 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-07-10 14:43:23 +0000
commit49616bb1f40cdd48affd1cdbadf969d43407c250 (patch)
tree48590dbfee34e78b5ed4d76bf66a567ce68763b1 /src/sbin
parent70b361d82ac3be583fa141c57311a97d8b2ab285 (diff)
downloadbcfg2-49616bb1f40cdd48affd1cdbadf969d43407c250.tar.gz
bcfg2-49616bb1f40cdd48affd1cdbadf969d43407c250.tar.bz2
bcfg2-49616bb1f40cdd48affd1cdbadf969d43407c250.zip
Commit client locking patch (From stousignant) (Resolves Ticket #575)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4770 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rwxr-xr-xsrc/sbin/bcfg219
1 files changed, 19 insertions, 0 deletions
diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2
index 5ac1e3aac..4757c129d 100755
--- a/src/sbin/bcfg2
+++ b/src/sbin/bcfg2
@@ -11,6 +11,7 @@ import sys
import tempfile
import time
import xmlrpclib
+import fcntl
import Bcfg2.Options
import Bcfg2.Client.XML
import Bcfg2.Client.Frame
@@ -31,6 +32,7 @@ def cb_sigint_handler(signum, frame):
DECISION_LIST = Bcfg2.Options.Option('Decision List', default=False,
cmd="--decision-list", odesc='<file>',
long_arg=True)
+LOCKFILE = "/var/lock/bcfg2.run"
class FPProxyCall(object):
def __init__(self, proxy, method):
@@ -117,6 +119,7 @@ class Client:
'key': Bcfg2.Options.SERVER_KEY,
'decision-list': DECISION_LIST,
'encoding': Bcfg2.Options.ENCODING,
+ 'omit-lock-check': Bcfg2.Options.OMIT_LOCK_CHECK,
}
self.setup = Bcfg2.Options.OptionParser(optinfo)
@@ -287,8 +290,24 @@ class Client:
times, self.setup['drivers'],
self.setup['dryrun'])
+ if not self.setup['omit-lock-check']:
+ #check lock here
+ lockfile = open(LOCKFILE, 'w')
+ try:
+ fcntl.lockf(lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ #otherwise exit and give a warning to the user
+ self.fatal_error("An other instance of bcfg2 is running. If you what to bypass the check, run with %s option" %
+ (Bcfg2.Options.OMIT_LOCK_CHECK.cmd))
+ return(1)
+ # execute the said configuration
self.tools.Execute()
+ if not self.setup['omit-lock-check']:
+ #unlock here
+ fcntl.lockf(lockfile.fileno(), fcntl.LOCK_UN)
+ os.remove(LOCKFILE)
+
if not self.setup['file']:
# upload statistics
feedback = self.tools.GenerateStats()