Commit a5cc4bfd authored by Ivar Refsdal's avatar Ivar Refsdal

Add gunicorn server

parent c83c37e1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import multiprocessing
import os
import re
import sys
import uuid
from logging import StreamHandler
import gunicorn.app.base
from gunicorn.six import iteritems
import flask_app
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
if __name__ == '__main__':
# See https://github.com/benoitc/gunicorn/blob/6a3bd70d2b6a8961f8bb1c16df58b4d7a3e83836/gunicorn/config.py
# for values
options = {
'workers' : (multiprocessing.cpu_count() * 2) + 1,
'logconfig' : 'gunicorn_logging.conf',
'timeout': 60*25, # 25 minutes timeout for worker process
'bind' : '0.0.0.0:8090'
}
StandaloneApplication(flask_app.app, options).run()
[loggers]
keys=root, gunicorn.error, gunicorn.access
[handlers]
keys=console
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_gunicorn.error]
level=INFO
handlers=console
propagate=0
qualname=gunicorn.error
[logger_gunicorn.access]
level=INFO
handlers=console
propagate=0
qualname=gunicorn.access
[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )
[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter
[formatter_access]
format=%(message)s
class=logging.Formatter
\ No newline at end of file
uWSGI==2.0.14
Werkzeug==0.11.8
flask==0.11.1
\ No newline at end of file
flask==0.11.1
gunicorn==19.6.0
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment