def make_http_servers(options, supervisord): servers = [] class LogWrapper: def log(self, msg): if msg.endswith('\n'): msg = msg[:-1] options.logger.trace(msg) wrapper = LogWrapper() for config in options.server_configs: family = config['family'] if family == socket.AF_INET: host, port = config['host'], config['port'] hs = supervisor_af_inet_http_server(host, port, logger_object=wrapper) elif family == socket.AF_UNIX: socketname = config['file'] sockchmod = config['chmod'] sockchown = config['chown'] hs = supervisor_af_unix_http_server(socketname,sockchmod, sockchown, logger_object=wrapper) else: raise ValueError('Cannot determine socket type %r' % family) from xmlrpc import supervisor_xmlrpc_handler from xmlrpc import SystemNamespaceRPCInterface from web import supervisor_ui_handler subinterfaces = [] for name, factory, d in options.rpcinterface_factories: try: inst = factory(supervisord, **d) except: import traceback; traceback.print_exc() raise ValueError('Could not make %s rpc interface' % name) subinterfaces.append((name, inst)) options.logger.info('RPC interface %r initialized' % name) subinterfaces.append(('system', SystemNamespaceRPCInterface(subinterfaces))) xmlrpchandler = supervisor_xmlrpc_handler(supervisord, subinterfaces) tailhandler = logtail_handler(supervisord) maintailhandler = mainlogtail_handler(supervisord) uihandler = supervisor_ui_handler(supervisord) here = os.path.abspath(os.path.dirname(__file__)) templatedir = os.path.join(here, 'ui') filesystem = filesys.os_filesystem(templatedir) defaulthandler = default_handler.default_handler(filesystem) username = config['username'] password = config['password'] if username: # wrap the xmlrpc handler and tailhandler in an authentication # handler users = {username:password} xmlrpchandler = supervisor_auth_handler(users, xmlrpchandler) tailhandler = supervisor_auth_handler(users, tailhandler) maintailhandler = supervisor_auth_handler(users, maintailhandler) uihandler = supervisor_auth_handler(users, uihandler) defaulthandler = supervisor_auth_handler(users, defaulthandler) else: options.logger.critical( 'Server %r running without any HTTP ' 'authentication checking' % config['section']) # defaulthandler must be consulted last as its match method matches # everything, so it's first here (indicating last checked) hs.install_handler(defaulthandler) hs.install_handler(uihandler) hs.install_handler(maintailhandler) hs.install_handler(tailhandler) hs.install_handler(xmlrpchandler) # last for speed (first checked) servers.append((config, hs)) return servers
def make_http_servers(options, supervisord): servers = [] wrapper = LogWrapper(options.logger) for config in options.server_configs: family = config['family'] if family == socket.AF_INET: host, port = config['host'], config['port'] hs = supervisor_af_inet_http_server(host, port, logger_object=wrapper) elif family == socket.AF_UNIX: socketname = config['file'] sockchmod = config['chmod'] sockchown = config['chown'] hs = supervisor_af_unix_http_server(socketname,sockchmod, sockchown, logger_object=wrapper) else: raise ValueError('Cannot determine socket type %r' % family) from xmlrpc import supervisor_xmlrpc_handler from xmlrpc import SystemNamespaceRPCInterface from web import supervisor_ui_handler subinterfaces = [] for name, factory, d in options.rpcinterface_factories: try: inst = factory(supervisord, **d) except: tb = traceback.format_exc() options.logger.warn(tb) raise ValueError('Could not make %s rpc interface' % name) subinterfaces.append((name, inst)) options.logger.info('RPC interface %r initialized' % name) subinterfaces.append(('system', SystemNamespaceRPCInterface(subinterfaces))) xmlrpchandler = supervisor_xmlrpc_handler(supervisord, subinterfaces) tailhandler = logtail_handler(supervisord) maintailhandler = mainlogtail_handler(supervisord) uihandler = supervisor_ui_handler(supervisord) here = os.path.abspath(os.path.dirname(__file__)) templatedir = os.path.join(here, 'ui') filesystem = filesys.os_filesystem(templatedir) defaulthandler = default_handler.default_handler(filesystem) username = config['username'] password = config['password'] if username: # wrap the xmlrpc handler and tailhandler in an authentication # handler users = {username:password} xmlrpchandler = supervisor_auth_handler(users, xmlrpchandler) tailhandler = supervisor_auth_handler(users, tailhandler) maintailhandler = supervisor_auth_handler(users, maintailhandler) uihandler = supervisor_auth_handler(users, uihandler) defaulthandler = supervisor_auth_handler(users, defaulthandler) else: options.logger.critical( 'Server %r running without any HTTP ' 'authentication checking' % config['section']) # defaulthandler must be consulted last as its match method matches # everything, so it's first here (indicating last checked) hs.install_handler(defaulthandler) hs.install_handler(uihandler) hs.install_handler(maintailhandler) hs.install_handler(tailhandler) hs.install_handler(xmlrpchandler) # last for speed (first checked) servers.append((config, hs)) return servers