]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
naoki: Add locking that only one batch operation can be run at a time.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Apr 2010 22:53:03 +0000 (00:53 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Apr 2010 22:53:03 +0000 (00:53 +0200)
naoki/__init__.py
naoki/constants.py

index 239d8f59845709695e9cccab6fb9b4a632a07b68..c95a52867bafb9b5e87fb41da36bd703a870dfb2 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import ConfigParser
+import fcntl
 import os.path
 import random
 import sys
@@ -323,6 +324,17 @@ Release       : %(release)s
                return gen.run()
 
        def call_batch(self, args):
+                try:
+                        self._lock = open(LOCK_BATCH, "a+")
+                except IOError, e:
+                        return 0
+
+                try:
+                        fcntl.lockf(self._lock.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
+                except IOError, e:
+                        print >>sys.stderr, "Batch operations are locked by another process"
+                       return 0
+
                actionmap = {
                        "cron" : self.call_batch_cron,
                }
index f77b00c4afe1e67c0a6481342bee48286f3a7b18..07c3ee317d61d604306523f76b30c5af663a0dcb 100644 (file)
@@ -27,6 +27,8 @@ CONFIGFILE = os.path.join(CONFIGDIR, "naoki.conf")
 
 CHROOT_PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
 
+LOCK_BATCH = os.path.join(BUILDDIR, ".batch")
+
 LOG_MARKER = "### LOG MARKER ###"
 
 def calc_parallelism():