summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-07-30 23:04:05 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-07-30 23:04:05 +0000
commitd04286b55daf7f4022ad78032d4f4b76ba713c8f (patch)
treee55b1753124e98ff0094f87a17d05e4951a6eb39 /src
parent6b649c0046395b7eb64e8e24d3433ee10dff2409 (diff)
downloadbcfg2-d04286b55daf7f4022ad78032d4f4b76ba713c8f.tar.gz
bcfg2-d04286b55daf7f4022ad78032d4f4b76ba713c8f.tar.bz2
bcfg2-d04286b55daf7f4022ad78032d4f4b76ba713c8f.zip
Fix pidfile handling and minor pylint fixes
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2012 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rwxr-xr-xsrc/sbin/bcfg2-server35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server
index 142ed766d..e78312e08 100755
--- a/src/sbin/bcfg2-server
+++ b/src/sbin/bcfg2-server
@@ -15,6 +15,25 @@ logger = logging.getLogger('bcfg2-server')
def daemonize(filename):
'''Do the double fork/setsession dance'''
+ # Check if the pid is active
+ try:
+ pidfile = open(filename, "r")
+ oldpid = int(pidfile.readline())
+ # getpgid() will retun an IO error if all fails
+ os.getpgid(oldpid)
+ pidfile.close()
+
+ # If we got this far without exceptions, there is another instance
+ # running. Exit gracefully.
+ logger.critical("PID File (%s) exists and listed PID (%d) is active." % \
+ (filename, oldpid) )
+ raise SystemExit, 1
+ except OSError:
+ pidfile.close()
+ except IOError:
+ # pid file doesn't
+ pass
+
# Fork once
if os.fork() != 0:
os._exit(0)
@@ -146,7 +165,7 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component):
raise Fault, (6, warning)
return True
- def Bcfg2GetConfig(self, address, image=False, profile=False):
+ def Bcfg2GetConfig(self, address, _=False, profile=False):
'''Build config for a client'''
client = self.resolve_client(address[0])
return tostring(self.Core.BuildConfiguration(client))
@@ -172,7 +191,7 @@ if __name__ == '__main__':
else:
Bcfg2.Logging.setup_logging('bcfg2-server')
- optinfo = {
+ OPTINFO = {
'verbose': (('-v', False, 'enable verbose output'),
False, False, False, True),
'debug': (('-d', False, 'enable debugging output'),
@@ -187,13 +206,13 @@ if __name__ == '__main__':
False, False, False, False)
}
- ssetup = Bcfg2.Options.OptionParser('bcfg2', optinfo).parse()
- if ssetup['daemon']:
- daemonize(ssetup['daemon'])
- s = Bcfg2Serv(ssetup)
- while not s.shut:
+ SSETUP = Bcfg2.Options.OptionParser('bcfg2', OPTINFO).parse()
+ if SSETUP['daemon']:
+ daemonize(SSETUP['daemon'])
+ BSERV = Bcfg2Serv(SSETUP)
+ while not BSERV.shut:
try:
- s.serve_forever()
+ BSERV.serve_forever()
except:
critical_error('error in service loop')
logger.info("Shutting down")