diff --git a/requirements.txt b/requirements.txt index 09afc05..e85b923 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,4 @@ python-dateutil==2.5.3 pytz==2016.7 requests==2.11.1 six==1.10.0 -Werkzeug==0.11.11 +gunicorn==19.6.0 diff --git a/setup.cfg b/setup.cfg index d824881..7828023 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,4 +52,4 @@ source-dir = releasenotes/source [entry_points] console_scripts = - valence = valence.run:main + valence = valence.cmd.api:main diff --git a/valence/cmd/__init__.py b/valence/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/valence/run.py b/valence/cmd/api.py similarity index 53% rename from valence/run.py rename to valence/cmd/api.py index 89ed654..ac295d0 100755 --- a/valence/run.py +++ b/valence/cmd/api.py @@ -14,16 +14,42 @@ # under the License. import logging + +import gunicorn.app.base +from gunicorn.six import iteritems + from valence.api.route import app as application from valence import config as cfg + LOG = logging.getLogger(__name__) +class StandaloneApplication(gunicorn.app.base.BaseApplication): + + def __init__(self, app, options=None): + self.options = options or {} + self.application = app + super(StandaloneApplication, self).__init__() + + def load_config(self): + config = dict([(key, value) for key, value in iteritems(self.options) + if key in self.cfg.settings and value is not None]) + for key, value in iteritems(config): + self.cfg.set(key.lower(), value) + + def load(self): + return self.application + + def main(): - application.run(host=cfg.bind_host, port=cfg.bind_port, debug=cfg.debug) + options = { + 'bind': '%s:%s' % (cfg.bind_host, cfg.bind_port) + } + StandaloneApplication(application, options).run() LOG.info(("Valence Server on http://%(host)s:%(port)s"), {'host': cfg.bind_host, 'port': cfg.bind_port}) + if __name__ == '__main__': main()