diff options
Diffstat (limited to 'src/sbin/bcfg2-server')
-rwxr-xr-x | src/sbin/bcfg2-server | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index 757172464..32c97b63d 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -2,74 +2,46 @@ """The XML-RPC Bcfg2 server.""" -import logging -import os.path +import os import sys - +import logging import Bcfg2.Logger import Bcfg2.Options -import Bcfg2.Component -import Bcfg2.Server.Plugins.Metadata from Bcfg2.Server.Core import CoreInitError logger = logging.getLogger('bcfg2-server') if __name__ == '__main__': - OPTINFO = { - 'configfile': Bcfg2.Options.CFILE, - 'daemon' : Bcfg2.Options.DAEMON, - 'debug' : Bcfg2.Options.DEBUG, - 'help' : Bcfg2.Options.HELP, - 'verbose' : Bcfg2.Options.VERBOSE, - 'to_file' : Bcfg2.Options.LOGGING_FILE_PATH, - 'repo' : Bcfg2.Options.SERVER_REPOSITORY, - 'plugins' : Bcfg2.Options.SERVER_PLUGINS, - 'password' : Bcfg2.Options.SERVER_PASSWORD, - 'fm' : Bcfg2.Options.SERVER_FILEMONITOR, - 'key' : Bcfg2.Options.SERVER_KEY, - 'cert' : Bcfg2.Options.SERVER_CERT, - 'ca' : Bcfg2.Options.SERVER_CA, - 'listen_all': Bcfg2.Options.SERVER_LISTEN_ALL, - 'location' : Bcfg2.Options.SERVER_LOCATION, - 'passwd' : Bcfg2.Options.SERVER_PASSWORD, - 'static' : Bcfg2.Options.SERVER_STATIC, - 'encoding' : Bcfg2.Options.ENCODING, - 'filelog' : Bcfg2.Options.LOGGING_FILE_PATH, - 'protocol' : Bcfg2.Options.SERVER_PROTOCOL, - } - - setup = Bcfg2.Options.OptionParser(OPTINFO) + optinfo = dict() + optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS) + optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS) + optinfo.update(Bcfg2.Options.DAEMON_COMMON_OPTIONS) + setup = Bcfg2.Options.OptionParser(optinfo) setup.parse(sys.argv[1:]) + # check whether the specified bcfg2.conf exists + if not os.path.exists(setup['configfile']): + print("Could not read %s" % setup['configfile']) + sys.exit(1) + + if setup['backend'] not in ['best', 'cherrypy', 'builtin']: + print("Unknown server backend %s, using 'best'" % setup['backend']) + setup['backend'] = 'best' + if setup['backend'] == 'cherrypy': + try: + from Bcfg2.Server.CherryPyCore import Core + except ImportError: + err = sys.exc_info()[1] + print("Unable to import CherryPy server core: %s" % err) + raise + elif setup['backend'] == 'builtin' or setup['backend'] == 'best': + from Bcfg2.Server.BuiltinCore import Core + try: - # check whether the specified bcfg2.conf exists - if not os.path.exists(setup['configfile']): - print("Could not read %s" % setup['configfile']) - sys.exit(1) - Bcfg2.Component.run_component(Bcfg2.Server.Core.Core, - listen_all=setup['listen_all'], - location=setup['location'], - daemon=setup['daemon'], - pidfile_name=setup['daemon'], - protocol=setup['protocol'], - to_file=setup['to_file'], - cfile=setup['configfile'], - register=False, - cls_kwargs={'repo':setup['repo'], - 'plugins':setup['plugins'], - 'password':setup['password'], - 'encoding':setup['encoding'], - 'ca':setup['ca'], - 'filemonitor':setup['fm'], - 'start_fam_thread':True, - 'setup':setup}, - keyfile=setup['key'], - certfile=setup['cert'], - ca=setup['ca'] - ) + core = Core(setup, start_fam_thread=True) + core.run() except CoreInitError: msg = sys.exc_info()[1] logger.error(msg) - logger.error("exiting") sys.exit(1) except KeyboardInterrupt: sys.exit(1) |