summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sbin/Bcfg2Server32
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)