简体   繁体   English

用于heroku的gunicorn和瓶子设置

[英]gunicorn & bottle setup for heroku

I was playing with bottle on heroku and wanted to switch for a more "production" WSGI server gunicorn. 我在heroku上玩瓶子,想换一个更“生产”的WSGI服务器gunicorn。 Here's my setup: 这是我的设置:

import os
import bottle
from bottle import route, run, template, request, static_file, error

class StripPathMiddleware(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, e, h):
        e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
        return self.app(e, h)

# ................................................................. #

@error(404)
def error404(error):
    return template('view/404.tpl')

app = bottle.app()
run(app=StripPathMiddleware(app), server='gunicorn', host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, workers=3)

And here's my Procfile : 这是我的Procfile

web: gunicorn SimpleServer:app -w 3

I tried Procfile with and without setting number of workers and so in the SimpleServer.py application. 我尝试在Procfile中设置和不设置工作程序数量,因此在SimpleServer.py应用程序中使用。

On a local machine it only works if in app I have workers=3 and I'm not specifying workers starting gunicorn : 在本地计算机上,只有在应用程序中我有worker = 3并且未指定工作人员启动gunicorn的情况下,它才有效:

(bottleServ)caerus@Artem:~/bottleServ$ gunicorn SimpleServer:app
2013-02-02 23:23:48 [18133] [INFO] Starting gunicorn 0.17.2
2013-02-02 23:23:48 [18133] [INFO] Listening at: http://127.0.0.1:8000 (18133)
2013-02-02 23:23:48 [18133] [INFO] Using worker: sync
2013-02-02 23:23:48 [18138] [INFO] Booting worker with pid: 18138
Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
Listening on http://0.0.0.0:5000/
Hit Ctrl-C to quit.

2013-02-02 23:23:48 [18138] [INFO] Starting gunicorn 0.17.2
2013-02-02 23:23:48 [18138] [INFO] Listening at: http://0.0.0.0:5000 (18138)
2013-02-02 23:23:48 [18138] [INFO] Using worker: sync
2013-02-02 23:23:48 [18139] [INFO] Booting worker with pid: 18139
2013-02-02 23:23:48 [18140] [INFO] Booting worker with pid: 18140
2013-02-02 23:23:48 [18141] [INFO] Booting worker with pid: 18141

But there's a problem with foreman start , doesn't matter what settings I use I get: 但是工头启动存在问题,无论我使用什么设置都无所谓:

(bottleServ)caerus@Artem:~/bottleServ$ foreman start
23:31:57 web.1  | started with pid 18192
23:31:58 web.1  | 2013-02-02 23:31:58 [18195] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1  | 2013-02-02 23:31:58 [18195] [INFO] Listening at: http://0.0.0.0:5000  (18195)
23:31:58 web.1  | 2013-02-02 23:31:58 [18195] [INFO] Using worker: sync
23:31:58 web.1  | 2013-02-02 23:31:58 [18200] [INFO] Booting worker with pid: 18200
23:31:58 web.1  | 2013-02-02 23:31:58 [18201] [INFO] Booting worker with pid: 18201
23:31:58 web.1  | 2013-02-02 23:31:58 [18202] [INFO] Booting worker with pid: 18202
23:31:58 web.1  | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1  | Listening on http://0.0.0.0:5000/
23:31:58 web.1  | Hit Ctrl-C to quit.
23:31:58 web.1  | 2013-02-02 23:31:58 [18202] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1  | 2013-02-02 23:31:58 [18202] [ERROR] Connection in use: ('0.0.0.0', 5000)
23:31:58 web.1  | 2013-02-02 23:31:58 [18202] [ERROR] Retrying in 1 second.
23:31:58 web.1  | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1  | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1  | Listening on http://0.0.0.0:5000/
23:31:58 web.1  | Listening on http://0.0.0.0:5000/
23:31:58 web.1  | Hit Ctrl-C to quit.
23:31:58 web.1  | Hit Ctrl-C to quit.
23:31:58 web.1  | 2013-02-02 23:31:58 [18200] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1  | 2013-02-02 23:31:58 [18201] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1  | 2013-02-02 23:31:58 [18200] [ERROR] Connection in use: ('0.0.0.0',   5000)
23:31:58 web.1  | 2013-02-02 23:31:58 [18201] [ERROR] Connection in use: ('0.0.0.0', 5000)
23:31:58 web.1  | 2013-02-02 23:31:58 [18200] [ERROR] Retrying in 1 second.
23:31:58 web.1  | 2013-02-02 23:31:58 [18201] [ERROR] Retrying in 1 second.

Any ideas would be appreciated! 任何想法,将不胜感激! )

You are starting gunicorn to run the app, and then using Bottle's 'run' to spawn another server (on Heroku, at least). 您正在启动gunicorn来运行该应用程序,然后使用Bottle的“运行”生成另一个服务器(至少在Heroku上)。 The reason you get the errors is that the initial server takes port 5000 and the second server can't access it. 出现错误的原因是,初始服务器占用了端口5000,而第二台服务器无法访问它。 Try just running your bottle app (python SimpleServer.py) it should create the server itself. 尝试仅运行您的Bottle应用程序(python SimpleServer.py),它会创建服务器本身。 Also, when you pass 'app' into run, the http server spawns another copy of your app (which spawns another gunicorn server), so just remove that. 另外,当您将“ app”传递给运行时,http服务器会生成您的应用程序的另一个副本(会生成另一个gunicorn服务器),因此只需删除该副本即可。

run(server='gunicorn', host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, workers=X)

python SimpleServer.py

Should be all you need. 应该是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM