diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2006-01-03 16:43:33 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2006-01-03 16:43:33 +0000 |
commit | 0dc85bf56ae4fbbbcbe85636dcfbeae81b66744d (patch) | |
tree | c959d0452314fb24188719defb3d389442d86532 /src/sbin | |
parent | f8f1b2d8a515948571d6f4ad558209c39965e8e6 (diff) | |
download | bcfg2-0dc85bf56ae4fbbbcbe85636dcfbeae81b66744d.tar.gz bcfg2-0dc85bf56ae4fbbbcbe85636dcfbeae81b66744d.tar.bz2 bcfg2-0dc85bf56ae4fbbbcbe85636dcfbeae81b66744d.zip |
re-add daemonization code
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1638 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rw-r--r-- | src/sbin/Bcfg2Server | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/sbin/Bcfg2Server b/src/sbin/Bcfg2Server index 8477fd4ca..ebeb8228d 100644 --- a/src/sbin/Bcfg2Server +++ b/src/sbin/Bcfg2Server @@ -18,6 +18,30 @@ from socket import gethostbyaddr, herror from lxml.etree import XML, Element, tostring from M2Crypto.SSL import SSLError +import os, sys + +def daemonize(filename): + '''Do the double fork/setsession dance''' + # Fork once + if os.fork() != 0: + os._exit(0) + os.setsid() # Create new session + pid = os.fork() + if pid != 0: + pidfile = open(filename, "w") + pidfile.write("%i" % pid) + pidfile.close() + os._exit(0) + os.chdir("/") + os.umask(0) + + null = open("/dev/null", "w+") + + os.dup2(null.fileno(), sys.__stdin__.fileno()) + os.dup2(null.fileno(), sys.__stdout__.fileno()) + os.dup2(null.fileno(), sys.__stderr__.fileno()) + + def critical_error(operation): '''Print tracebacks in unexpected cases''' syslog(LOG_ERR, "Traceback information (please include in any bug report):") @@ -165,7 +189,7 @@ class Bcfg2(Component): resp = Element('probes') try: - meta = self.Core.metadata.FetchMetadata(client) + meta = self.Core.metadata.get_metadata(client) for generator in self.Core.generators: for probe in generator.GetProbes(meta): @@ -199,9 +223,7 @@ class Bcfg2(Component): if image and profile: try: - # if metadata is provided, call FetchMetadata with settings - # it is screwy. i know. - self.Core.metadata.FetchMetadata(client, image=image, profile=profile) + self.Core.metadata.set_group(client, profile) except MetadataConsistencyError: warning = 'metadata consistency error' warning_error(warning) @@ -253,6 +275,8 @@ if __name__ == '__main__': ssetup = dgetopt(argv[1:], options, doptions, descriptions, argDescriptions) + if ssetup['daemon']: + daemonize(ssetup['daemon']) if not ssetup['configfile']: ssetup['configfile'] = '/etc/bcfg2.conf' s = Bcfg2(ssetup) |