From 97c928350ce0a593856e2a5ada8f8bcb0c27324e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 2 Jul 2015 13:23:48 -0400 Subject: [PATCH] Provide for configuration file specification of http listen Establish a config file for certain configuration parameters that control service startup and things that are best managed via out of band configuration file and easiest to do with a restart. For now, implement control of http service binding. From Lucio Seki --- confluent_server/confluent/httpapi.py | 10 ++++++---- confluent_server/confluent/main.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index c725a6ad..9aea1ea6 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -507,7 +507,7 @@ def _assemble_json(responses, resource, url, extension): rspdata, sort_keys=True, indent=4, ensure_ascii=False).encode('utf-8') -def serve(): +def serve(bind_host, bind_port): # TODO(jbjohnso): move to unix socket and explore # either making apache deal with it # or just supporting nginx or lighthttpd @@ -519,20 +519,22 @@ def serve(): #also, the potential for direct http can be handy #todo remains unix domain socket for even http eventlet.wsgi.server( - eventlet.listen(('::', 4005, 0, 0), family=socket.AF_INET6), + eventlet.listen((bind_host, bind_port, 0, 0), family=socket.AF_INET6), resourcehandler, log=False, log_output=False, debug=False) class HttpApi(object): - def __init__(self): + def __init__(self, bind_host=None, bind_port=None): self.server = None + self.bind_host = bind_host or '::' + self.bind_port = bind_port or 4005 def start(self): global auditlog global tracelog tracelog = log.Logger('trace') auditlog = log.Logger('audit') - self.server = eventlet.spawn(serve) + self.server = eventlet.spawn(serve, self.bind_host, self.bind_port) _cleaner = eventlet.spawn(_sessioncleaner) diff --git a/confluent_server/confluent/main.py b/confluent_server/confluent/main.py index b03f639d..edd653fc 100644 --- a/confluent_server/confluent/main.py +++ b/confluent_server/confluent/main.py @@ -39,6 +39,7 @@ import fcntl import sys import os import signal +import ConfigParser def _daemonize(): @@ -115,6 +116,7 @@ def doexit(): def run(): + configfile = "/etc/confluent/service.cfg" _checkpidfile() confluentcore.load_plugins() _daemonize() @@ -127,8 +129,16 @@ def run(): #dbgsock = eventlet.listen("/var/run/confluent/dbg.sock", # family=socket.AF_UNIX) #eventlet.spawn_n(backdoor.backdoor_server, dbgsock) + config = ConfigParser.ConfigParser() + config.read(configfile) + try: + bind_host = config.get('http', 'bindhost') + bind_port = config.getint('http', 'bindport') + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: + bind_host = None + bind_port = None consoleserver.start_console_sessions() - webservice = httpapi.HttpApi() + webservice = httpapi.HttpApi(bind_host, bind_port) webservice.start() sockservice = sockapi.SockApi() sockservice.start()