Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heroku $PORT variable in Procfile

Hi have a Django project that I want to deploy on heroku. My procfile looks like this:

web: python subfolder/manage.py runserver $PORT

But my heroku logs tell me that the application did not bind to the port within the required time.

2014-04-17T15:35:20.294741+00:00 heroku[api]: Deploy c456cc6 by [email protected]
2014-04-17T15:35:20.294830+00:00 heroku[api]: Release v17 created by [email protected]
2014-04-17T15:35:31.447035+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 14311`
2014-04-17T15:35:32.949252+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '14311']
2014-04-17T15:35:33.286494+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '14311']
2014-04-17T15:35:33.296080+00:00 app[web.1]: Validating models...
2014-04-17T15:35:33.296084+00:00 app[web.1]: 
2014-04-17T15:35:33.434037+00:00 app[web.1]: 0 errors found
2014-04-17T15:35:33.434129+00:00 app[web.1]: April 17, 2014 - 10:35:33
2014-04-17T15:35:33.434131+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15:35:33.434133+00:00 app[web.1]: Starting development server at http://127.0.0.1:14311/
2014-04-17T15:35:33.434134+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:36:31.995497+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:36:31.995711+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:36:33.512080+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:36:33.526505+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T15:36:33.527696+00:00 heroku[web.1]: State changed from crashed to starting
2014-04-17T15:36:42.946854+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 9192`
2014-04-17T15:36:43.989111+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '9192']
2014-04-17T15:36:44.294956+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '9192']
2014-04-17T15:36:44.302783+00:00 app[web.1]: Validating models...
2014-04-17T15:36:44.302787+00:00 app[web.1]: 
2014-04-17T15:36:44.447995+00:00 app[web.1]: 0 errors found
2014-04-17T15:36:44.448008+00:00 app[web.1]: April 17, 2014 - 10:36:44
2014-04-17T15:36:44.448009+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15:36:44.448010+00:00 app[web.1]: Starting development server at http://127.0.0.1:9192/
2014-04-17T15:36:44.448012+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:37:43.446630+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:37:43.446759+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:37:43.456335+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=my-app.herokuapp.com request_id=7eed5b88-2bb3-479e-b268-f538742d8ac9 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:37:44.608835+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:37:44.625259+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T15:39:18.516212+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=145aa053-bb2b-4570-8ba6-fa88f2a5b1a6 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:47:22.827631+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=fe43143f-defd-4756-a61c-e9558dd15ae6 fwd="91.52.58.207" dyno= connect= service= status=503 bytes=
2014-04-17T15:57:27.577848+00:00 heroku[web.1]: State changed from crashed to starting
2014-04-17T15:57:37.742542+00:00 heroku[web.1]: Starting process with command `python subfolder/manage.py runserver 10935`
2014-04-17T15:57:39.224244+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '10935']
2014-04-17T15:57:39.788496+00:00 app[web.1]: Django version 1.6.2, using settings 'subfolder.settings'
2014-04-17T15
:57:39.788498+00:00 app[web.1]: Starting development server at http://127.0.0.1:10935/
2014-04-17T15:57:39.618885+00:00 app[web.1]: >>> sys.argv: ['subfolder/manage.py', 'runserver', '10935']
2014-04-17T15:57:39.788500+00:00 app[web.1]: Quit the server with CONTROL-C.
2014-04-17T15:57:39.636416+00:00 app[web.1]: Validating models...
2014-04-17T15:57:39.636420+00:00 app[web.1]: 
2014-04-17T15:57:39.788202+00:00 app[web.1]: 0 errors found
2014-04-17T15:57:39.788493+00:00 app[web.1]: April 17, 2014 - 10:57:39
2014-04-17T15:58:38.275475+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-04-17T15:58:38.275554+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-04-17T15:58:39.572038+00:00 heroku[web.1]: Process exited with status 137
2014-04-17T15:58:39.588577+00:00 heroku[web.1]: State changed from starting to crashed
2014-04-17T16:04:48.672005+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=my-app.herokuapp.com request_id=fc101c45-45c0-4e46-ad26-a7953619525e fwd="91.52.58.207" dyno= connect= service= status=503 bytes=

It seems like $PORT differs from some time to time. The heroku config however says the following:

(.env) $ heroku config
=== my-app Config Vars
PORT: 33507

Why doesn't it work?

like image 212
Niklas R Avatar asked Apr 17 '14 16:04

Niklas R


1 Answers

By default the development server binds to localhost only, you must specific that you want to bind to any IP:

web: python subfolder/manage.py runserver 0.0.0.0:$PORT

But running the dev server in production is a very bad idea. You really should be using gunicorn or some other proper server to deploy your project:

web: gunicorn subfolder/yourproject.wsgi

Follow the steps on https://devcenter.heroku.com/articles/getting-started-with-django if you need more guidance.

like image 97
Yuval Adam Avatar answered Oct 01 '22 22:10

Yuval Adam