blob: 8322edeaa2e704d36f5298a01d85352f657c5ca3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/env python
"""The XML-RPC Bcfg2 server."""
import os
import sys
import logging
import Bcfg2.Logger
import Bcfg2.Options
from Bcfg2.Server.Core import CoreInitError
LOGGER = logging.getLogger('bcfg2-server')
def main():
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:
core = Core(setup)
core.run()
except CoreInitError:
msg = sys.exc_info()[1]
LOGGER.error(msg)
sys.exit(1)
except KeyboardInterrupt:
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':
sys.exit(main())
|