2013-02-02 84 views
2

我在heroku上玩瓶子,想換一個更「生產」的WSGI服務器gunicorn。這裏是我的設置:gunicorn&bottle設置爲heroku

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) 

這是我的Procfile

web: gunicorn SimpleServer:app -w 3 

我試圖Procfile有和沒有設置的工人數量,所以在SimpleServer.py應用。

在本地機器,如果在應用程序我有工人= 3它只能和我沒有指定起點gunicorn工人:

(bottleServ)[email protected]:~/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 

但是有一個問題工頭開始,不要緊,我使用什麼設置我得到:

(bottleServ)[email protected]:~/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. 

任何想法,將不勝感激! )

回答

4

您正在啓動gunicorn來運行應用程序,然後使用Bottle's 'run'來產生另一臺服務器(至少在Heroku上)。出現錯誤的原因是初始服務器端口5000,第二臺服務器無法訪問。嘗試運行你的瓶子應用程序(python SimpleServer.py)它應該創建服務器本身。另外,當你傳遞'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 

應該是你所需要的。

+0

謝謝,這是有道理的。我錯過了一個WSGI「應用程序」對象。 [tutorial here](http://blog.yprez.com/running-a-bottle-app-with-gunicorn.html) – justartem

+0

有同樣的問題。刪除app.run()爲我工作。謝謝! – tmthyjames