From 57054f1a4c77d8a9f5dc25c6439996fa375e4cd9 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Wed, 27 Jan 2010 16:08:08 +0100 Subject: [PATCH] don't set default values for command line options so we can use paster one and later our own conf. While I'm here display the address on which we start to listen so we can get the port when using port=0. --- bin/gunicorn_paste | 4 ++++ gunicorn/arbiter.py | 2 ++ gunicorn/main.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/gunicorn_paste b/bin/gunicorn_paste index 524f3850..1703893d 100644 --- a/bin/gunicorn_paste +++ b/bin/gunicorn_paste @@ -63,12 +63,16 @@ def get_app(parser, opts, args): else: workers = int(ctx.local_conf.get('workers', 1)) + opts.host = opts.host or ctx.local_conf.get('host', '127.0.0.1') + opts.port = opts.port or int(ctx.local_conf.get('port', 8000)) + debug = ctx.global_conf.get('debug') == "true" if debug: # we force to one worker in debug mode. workers = 1 opts.workers=workers + app = loadapp(config_url, relative_to=relative_to) return app diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 19f9fa74..e4eee544 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -92,6 +92,8 @@ class Arbiter(object): if i < 5: self.log.error("Retrying in 1 second.") time.sleep(1) + if self.LISTENER: + self.log.info("Listen on %s:%s" % self.LISTENER.getsockname()) def init_socket_fromfd(self, fd, address): sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) diff --git a/gunicorn/main.py b/gunicorn/main.py index 52ced03f..6c103ca9 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -19,9 +19,9 @@ LOG_LEVELS = { def options(): return [ - op.make_option('--host', dest='host', default='127.0.0.1', + op.make_option('--host', dest='host', help='Host to listen on. [%default]'), - op.make_option('--port', dest='port', default=8000, type='int', + op.make_option('--port', dest='port', type='int', help='Port to listen on. [%default]'), op.make_option('--workers', dest='workers', type='int', help='Number of workers to spawn. [%default]'), @@ -57,8 +57,17 @@ def main(usage, get_app): workers = opts.workers or 1 if opts.debug: workers = 1 + + host = opts.host or '127.0.0.1' + port = opts.port + if port is None: + if ':' in host: + host, port = host.split(':', 1) + port = int(port) + else: + port = 8000 - arbiter = Arbiter((opts.host, opts.port), workers, app, + arbiter = Arbiter((host,port), workers, app, opts.debug) arbiter.run()