From 592d406208fb387fc14b5ec2663804d9f6a22a49 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Tue, 6 Dec 2005 18:50:52 +0000 Subject: Re-add daemonize support to the server Fix some pylint errors Add better error handling for function calls Add mesh-mode support for sshbase git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1612 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/Bcfg2Server | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/sbin') diff --git a/src/sbin/Bcfg2Server b/src/sbin/Bcfg2Server index 8b2423355..d8e224369 100644 --- a/src/sbin/Bcfg2Server +++ b/src/sbin/Bcfg2Server @@ -17,6 +17,7 @@ from xmlrpclib import Fault from socket import gethostbyaddr, herror from lxml.etree import XML, Element, tostring from M2Crypto.SSL import SSLError +import os, sys def dgetopt(arglist, opt, vopt): '''parse options into a dictionary''' @@ -174,6 +175,23 @@ if __name__ == '__main__': ssetup = dgetopt(argv[1:], options, doptions) if not ssetup['configfile']: ssetup['configfile'] = '/etc/bcfg2.conf' + if ssetup['daemon']: + if os.fork() != 0: + os._exit(0) + os.setsid() # Create new session + pid = os.fork() + if pid != 0: + pidfile = open(ssetup['daemon'], "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()) + s = Bcfg2(ssetup) while not s.shut: try: -- cgit v1.2.3-1-g7c22