def paste_server(app, global_conf=None, host="127.0.0.1", port=None, *args, **kwargs): """ Paster server entrypoint to add to your paster ini file: [server:main] use = egg:gunicorn#main host = 127.0.0.1 port = 5000 """ options = kwargs.copy() if port and not host.startswith("unix:"): bind = "%s:%s" % (host, port) else: bind = host options['bind'] = bind if global_conf: for key, value in list(global_conf.items()): if value and value is not None: if key == "debug": value = (value == "true") options[key] = value options['default_proc_name'] = options['__file__'] conf = Config(options) arbiter = conf.arbiter(conf.address, conf.workers, app, debug=conf["debug"], pidfile=conf["pidfile"], config=conf) if conf["daemon"] : daemonize() else: os.setpgrp() configure_logging(conf) arbiter.run()
def handle(self, addrport='', *args, **options): if args: raise CommandError('Usage is runserver %s' % self.args) options['bind'] = addrport or '127.0.0.1' options['default_proc_name'] =settings.SETTINGS_MODULE conf = Config(options, options.get('gconfig')) admin_media_path = options.get('admin_media_path', '') quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) print "Development server is running at %s" % str(conf.address) print "Quit the server with %s." % quit_command # django.core.management.base forces the locale to en-us. translation.activate(settings.LANGUAGE_CODE) try: handler = AdminMediaHandler(WSGIHandler(), admin_media_path) arbiter = conf.arbiter(conf.address, conf.workers, handler, pidfile=conf['pidfile'], config=conf) if conf['daemon']: daemonize() else: os.setpgrp() configure_logging(conf) arbiter.run() except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { 13: "You don't have permission to access that port.", 98: "That port is already in use.", 99: "That IP address can't be assigned-to.", } try: error_text = ERRORS[e.args[0].args[0]] except (AttributeError, KeyError): error_text = str(e) sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n') sys.exit(1)
def main(usage, get_app): """ function used by different runners to setup options ans launch the arbiter. """ parser = op.OptionParser(usage=usage, option_list=options(), version="%prog " + __version__) opts, args = parser.parse_args() app = get_app(parser, opts, args) conf = Config(opts.__dict__, opts.config) arbiter = conf.arbiter(conf.address, conf.workers, app, config=conf, debug=conf['debug'], pidfile=conf['pidfile']) if conf['daemon']: daemonize() else: os.setpgrp() configure_logging(conf) arbiter.run()