I'm trying to deploy my django app on heroku. After following the steps instructed by the official document, the dyno I launched always crashes. Then I went through the whole process, and I think the problem might lie on the gunicorn part.
Following the instruction, I set the Procfile as 'web: unicorn hellodjango.wsgi', and when I $foreman start, it only shows "21:21:07 web.1 | started with pid 77969". It didn't say where the web is launched.
Then I tried to test whether gunicorn is working well. So I tried: "$gunicorn hellodjango.wsgi:application", it indeed doesn't work.
I think the path is correct because in current folder there's a hellodjango folder and inside there's the file wsgi.py.
What might be the problem?
One of the changes in later versions of gunicorn includes not logging to stdout/stderr. Add the argument --log-file=XXX, then examine that log file for what port it's running on.
Try setting your Procfile to:
web: gunicorn hellodjango.wsgi:application
write this in your Procfile:
web: gunicorn hellodjango.wsgi --log-file -
it will log everything to the screen like this:
(your_virtualenv)[~/Projects/myproj]$ foreman start
17:03:57 web.1 | started with pid 79137
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Starting gunicorn 19.0.0
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Listening at: http://0.0.0.0:5000 (79137)
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Using worker: sync
17:03:58 web.1 | 2014-10-16 17:03:58 [79140] [INFO] Booting worker with pid: 79140
Related
How to configure gunicorn to make sure my python-flask website is available 24*7 ?
The issue I am facing is: As soon I kill my terminal window, the website is no more reachable.
I am using rhel7.6 to host a website using python-flask.
I have configured nginx as the web server and gunicorn as the application server.
.
I will really appreciate if some one can help me in using/configuring gunicorn to make sure my website is available 24*7.
Please have some of my code as below:
[root#syed-dashboard-4 ~]# pwd
/root
[root#syed-dashboard-4 ~]#
[root#syed-dashboard-4 ~]# cat hello.py
#!/usr/bin/python
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello magentabox!"
#if __name__ == "__main__":
# app.run(host='10.145.29.23',port=5000)
[root#syed-dashboard-4 ~]#
[root#syed-dashboard-4 ~]# gunicorn hello:app
[2019-07-17 10:34:11 +0000] [9346] [INFO] Starting gunicorn 19.9.0
[2019-07-17 10:34:11 +0000] [9346] [INFO] Listening at: http://127.0.0.1:8000 (9346)
[2019-07-17 10:34:11 +0000] [9346] [INFO] Using worker: sync
[2019-07-17 10:34:11 +0000] [9351] [INFO] Booting worker with pid: 9351
I am pretty new to web development and as I mentioned as soon I close the terminal, the website is no more reachable. I can share the nginx configuration logs as well if that helps fixing my issue.
Thanks much.
You can use the supervisor. This is the professional way to run your server for 24*7.
Please add below file in your supervisor config to run.
[program:your_project_name]
command=/home/virtualenvpath/your_env/bin/gunicorn --log-level debug run_apiengine:main_app --bind 0.0.0.0:5006 --workers 5 --worker-class gevent
stdout_logfile=/home/your_path_to_log/supervisor_stdout.log
stderr_logfile=/home/your_path_to_log/supervisor_stderr.log
user=your_user
autostart=true
autorestart=true
environment=PYTHONPATH="$PYTHONPATH:/home/path_to_your_project";OAUTHLIB_INSECURE_TRANSPORT='1';
Configure this in supervisor it will run for 24*7. And whenever your machine restarts it will auto start.
On Linux, you can start your app in a tmux session that you detach once you started your server.
# Create a new tmux session
tmux new -s server
# Start your gunicorn server
cd /path/to/app
gunicorn hello:app
# Detach the current tmux session using Ctrl - B + D
You can close your terminal and your server will still be running.
I am trying to deploy my app using Google App Engine. I have edited app.yaml to reflect the flexible environment and also gave all the app information. Below is the app.yaml file.
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
Once the deployment is in progress, I am getting the following error
[2018-08-24 06:57:14 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-08-24 06:57:14 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-08-24 06:57:14 +0000] [1] [INFO] Using worker: sync
[2018-08-24 06:57:14 +0000] [7] [INFO] Booting worker with pid: 7
App Deployed
Failed to find application: 'main'
[2018-08-24 06:57:14 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-08-24 06:57:14 +0000] [1] [INFO] Shutting down: Master
[2018-08-24 06:57:14 +0000] [1] [INFO] Reason: App failed to load.
Please note that App Deployed is the line in my print statement. It is getting executed. But the deployment is getting failed
Thank you in advance
In your app.yaml, you're starting gunicorn with gunicorn -b :$PORT main:app. This tells it to look for the object app in the file main.py
The error you're getting comes from gunicorn and occurs when you have a main.py file, but it does not have an app object in it.
You probably want to set up a Flask app as follows:
from flask import Flask
app = Flask(__name__)
See a full example app here: https://cloud.google.com/appengine/docs/flexible/python/quickstart#hello_world_code_review
I have had the same issue.
Failed to find application: 'main'
The reason in my case was that I had a directory called also main in the root project directory.
drwxr-xr-x 2 user staff 64 Nov 30 10:12 main
-rw-r--r-- 1 user staff 1178 Nov 29 20:58 main.py
I guess gunicorn got confused.
The solution (worked for me): to rename main directory.
P.S. Just don't rename it to code directory. It will cause another issue with debugging in PyCharm. :)
My folder structure is looks llike this the main.py is not in the root directory how I can specify this in app.yaml file.
/app
|__main.py
app.yaml
I have deployed a django app and deployed to Heroku it takes facebook account id's as input through CSV file
and parses information. it works fine in the local server but I am getting the below mentioned error when I try to upload a larger CSV file.
14:12:16 web.1 | 2014-07-17 14:12:16 [30747] [INFO] Using worker: sync
14:12:16 web.1 | 2014-07-17 14:12:16 [30752] [INFO] Booting worker with pid: 30752
14:13:21 web.1 | 2014-07-17 14:13:21 [30747] [CRITICAL] WORKER TIMEOUT (pid:30752)
14:13:21 web.1 | 2014-07-17 03:43:21 [30752] [INFO] Worker exiting (pid: 30752)
14:13:21 web.1 | 2014-07-17 14:13:21 [30841] [INFO] Booting worker with pid: 30
Heroku requests are limited to 30 seconds, if the request take longer than this the router will terminate the request
You can increase the LOG LEVEL of gunicorn to see if there's some error in your process
Example of Procfile with timeout increased to 15 sec
web: gunicorn myproject.wsgi --timeout 15 --keep-alive 5 --log-level debug
I cannot seem to find a solid answer to this after scouring the web for answers. Currently, I have my directory set up this way:
flaskapp
-app
-intro_to_flask
+__init__.py
+config.py
+routes.py
+forms.py
-runserver.py
-Readme.md
-bin
-include
-lib
-view
Procfile
requirements.txt
So I not sure whether the Procfile is set up correctly...I have it set up this way:
web: gunicorn --pythonpath app runserver
However, when I run foreman start...heroku goes into a loop that keeps restarting the connection, I tried manually setting the port in the virtual environment export PORT=5001, but I am still getting the same error:
Running on http://127.0.0.1:5000/
12:21:20 web.1 | * Restarting with reloader
12:21:20 web.1 | 2014-02-22 12:21:20 [34532] [INFO] Starting gunicorn 18.0
12:21:20 web.1 | 2014-02-22 12:21:20 [34532] [ERROR] Connection in use: ('0.0.0.0', 5001)
Also, I have killed all gunicorn processes that are in used and tried running foreman start again...any ideas what could be going on?
Here is my runserver.py
from intro_to_flask import app
app.run(debug=True)
When you run your app on gunicorn you do not use the same starter script that starts the development server. All gunicorn needs to know is from where to import the application. In your case I think what you want in your Procfile is something like this:
web: gunicorn --pythonpath app intro_to_flask:app
Not sure if this will work as is or if you will need to make minor tweaks. The idea is that you need to give gunicorn the package or module that defines the application, then a colon, and then the application instance symbol.
I hope this helps.
I am following Getting Started with Django on Heroku tutorial to deploy my app. First to test locally, I ran foreman start:
| => foreman start
00:47:08 web.1 | started with pid 4465
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Starting gunicorn 18.0
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Listening at: http://0.0.0.0:5000 (4465)
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Using worker: sync
00:47:09 web.1 | 2013-11-21 00:47:09 [4468] [INFO] Booting worker with pid: 4468
Then in Chrome I went to http://0.0.0.0:5000/rides/ (also http://localhost:5000/rides/), it is returning Server Error 500.
My project urls.py:
url(r'^rides/', include('rides.urls')),
url(r'^admin/', include(admin.site.urls)),
Below is my Procfile:
web: gunicorn rides_project.wsgi
requirements.txt:
Django==1.6
South==0.8.3
dj-database-url==0.2.2
dj-static==0.0.5
django-localflavor==1.0
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.1
static==0.4
wsgiref==0.1.2
How can I troubleshoot this? Thank you for your help in advance.
Can you navigate to /admin successfully? If so, I would ensure that your DEBUG setting is set to True so that you can get a traceback through the browser to help determine the root cause of the 500 error.