問題描述
Heroku 無法啟動我的應用程序,但 foreman start
工作 (Heroku fails to start my app, but foreman start
works)
I'm attempting to deploy a fairly simple Flask app to Heroku's cedar stack, but I keep seeing the following error:
2012‑08‑09T22:37:49+00:00 heroku[web.1]: State changed from crashed to starting
2012‑08‑09T22:37:52+00:00 heroku[web.1]: Starting process with command `gunicorn pytips.app:create_app() ‑b 0.0.0.0:42152 ‑w 3`
2012‑08‑09T22:37:53+00:00 app[web.1]: bash: ‑c: line 0: syntax error near unexpected token `('
2012‑08‑09T22:37:53+00:00 app[web.1]: bash: ‑c: line 0: `gunicorn pytips.app:create_app() ‑b 0.0.0.0:42152 ‑w 3'
And I have this as my Procfile
:
web: gunicorn pytips.app:create_app() ‑b 0.0.0.0:$PORT ‑w 3
When I test this locally by running foreman start
, things work just fine. Why is Heroku having problems if foreman
is fine with it locally?
UPDATE: I've also tried testing with heroku run
. Here's what that yields:
heroku run ‑‑app pytips gunicorn pytips.app:create_app() ‑b 0.0.0.0:$PORT ‑w 3
gives me nothing.
heroku run ‑‑app pytips 'gunicorn pytips.app:create_app() ‑b 0.0.0.0:$PORT ‑w 3'
gives me heroku:108: command not found: ‑b
.
‑‑‑‑‑
參考解法
方法 1:
My current solution is this: I escape the parentheses, e.g.,
web: gunicorn pytips.app:create_app\(\) ‑b 0.0.0.0:$PORT ‑w 3
While this totally explodes on my local box, it seems to work just peachy on Heroku's system. I am still hoping the support team at Heroku can figure out why it works in one place, but not the other. Until then, I will just test locally with the the unescaped version, then put the escapes back before pushing to Heroku.
方法 2:
I was getting the same error 500s with nothing in the logs.
Turned out that Heroku did not like my local SQLite database. I was able to set up the free PostgreSQL database and the error went away.
I followed this tutorial.
http://blog.y3xz.com/blog/2012/08/16/flask‑and‑postgresql‑on‑heroku/
方法 3:
so the first thing is your gunicorn
command is incorrect. When you run gunicorn, you need to pass it your app instance. So for example, if your Flask app is defined inside a pytips.py
file, you would run gunicorn by doing: gunicorn pytips:app ‑b ...
.
If you change that, I'm guessing it will work fine, as the rest of your stuff looks good.
(by Hank Gay、Hank Gay、Nick Woodhams、rdegges)