summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Options.py2
-rwxr-xr-xsrc/sbin/bcfg219
2 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/Options.py b/src/lib/Options.py
index 712b5a5f9..3c5b3979a 100644
--- a/src/lib/Options.py
+++ b/src/lib/Options.py
@@ -249,6 +249,8 @@ AGENT_HOST = Option('Remote host', default=False, cmd='-H', odesc='<hostname>')
ENCODING = Option('Encoding of cfg files', default=sys.getdefaultencoding(), cmd='-E', odesc='<encoding>',
cf=('components', 'encoding'))
+OMIT_LOCK_CHECK = Option('Omit lock check', default=False, cmd='-O')
+
class OptionParser(OptionSet):
'''OptionParser bootstraps option parsing, getting the value of the config file'''
def __init__(self, args):
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()